Advertisement: Linux VPS for $4/month - based on OpenVZ, credit card accepted, automatic setup.
+ Post New Thread
Results 1 to 2 of 2

Thread: How to run linux command on background in bash(shell) script ?

  1. #1
    Administrator Fli's Avatar
    Join Date
    Mar 2013
    Posts
    2,236
    Post Thanks / Like
    Blog Entries
    1

    How to run linux command on background in bash(shell) script ?



    Hello, i just want to share this bash script code.

    # definning emptybuffer function which will sleep 3600 seconds and empty buffer file when called.
    # these commands (sleep, >) will be executed on background and script can continue to run
    emptybuffer(){
    sleep 3600
    >/root/script/buffer

    }

    # if there is no "sleep 3600" process running, then we execute it (function emptybuffer)
    if [ "$(ps x | grep "sleep 3600" | wc -l)" -lt "2" ];then
    emptybuffer &
    fi
    Please if you know any other ways to simply execute linux command from bash script on background, please kindly share, thx

  2. #2
    Junior Member imort's Avatar
    Join Date
    Apr 2016
    Posts
    15
    Post Thanks / Like


    Is this useful / helpfull? Yes | No
    Quote Originally Posted by admin View Post
    Hello, i just want to share this bash script code.
    Please if you know any other ways to simply execute linux command from bash script on background, please kindly share, thx
    You can just run the command like that:

    ./your_script.sh &
    and it will be executed in the background return some result and finished.

+ Post New Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
 Protected by : ZB BLOCK  &  StopForumSpam