Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    How to run bash script so it has speciffic name in the process list?


    Hello,

    i need to keep running one bash script. And if it gets killed or stoped by any reason, i need to start it again as soon as possible.

    I could create cron task to run it and in the script create condition based on ps aux results to see if it already running. If running i will exit the script and do not continue.

    But in process list i cant find the script, only sometimes commands it is using.

    // update: when run "./scriptname" i cant find, but when run "sh ./scriptname" i can see "sh scriptname" in the process list
    Last edited by postcd; 07-30-2016 at 09:15 AM.
    https://zeronet.io - Open, free and uncensorable websites, using Bitcoin cryptography and BitTorrent network

  2. #2
    Linux Engineer
    Join Date
    Jan 2005
    Location
    Saint Paul, MN
    Posts
    818
    Rename the file of script to be the name you desire to see in the PS.

    Add the first line:
    Code:
    #!/bin/bash
    Make it marked as "executable" one of the following:
    Code:
    chmod 700 filename
    chmod 750 filename
    chmod 770 filename
    chmod 755 filename
    chmod 775 filename
    chmod 777 filename
    Run the script with its location in the PATH environment variable, with the qualified path, or a relative path such as ./filename

  3. #3
    Use the script's ps id instead :
    Code:
    echo $#

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru
    Join Date
    Dec 2013
    Posts
    2,747
    -->
    what exact command are you using to find the process? ps has many more options than "aux", i'm sure one of them can find your script.
    or, have you tried "pidof -x scriptname"?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •