Score:0

Run apps with redirection from within a shell script

br flag

I have a watchdog script that runs applications listed in a file. I want to be able to run the applications as entered in that file. Currently I am just looping thru the file and running them in the background if there is no pid associated with those apps, I simply run app with (list_Entry &) to allow all arguments that app might have and redirections of I/O intact. While arguments are working properly, its not working for the listEntry that looks like "my_app >> /tmp/mylog.txt 2>&1", the redirection argument doesn't create a /tmp/mylog, instead stdout gets routed to my script. How can I prevent this from hapening?

while true
do
  test /mnt/appsList && {
    input="/mnt/appsList"
    while IFS= read -r line
    do
    if echo $line | grep -q  "^[a-z/(]"; then
      app_base=$(basename `echo "$line"|cut -f1 -d ' '|tr -d [:space:]`)
      #echo "testing run status for $app_base"
      pid_app=$(pgrep -f $app_base)
      # echo "`date` : pid of $app_base is $pid_app" | tee -a  $_SYS_LOG_DIR/system_log

      if [ -z "$pid_app" ];then
         echo "`date` : Running $line " | tee -a  $_SYS_LOG_DIR/system_log
         ($line) &
         sleep 10
      fi
    fi
    done < "$input"
  }
sleep 5
done

Thanks Ratin

hr flag
Please [edit] your question to include a minimal example of your script
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.