0

I want to start a simple daemon process in Ubuntu, which will write the current time to log file every 5 seconds.

 start-stop-daemon --start --user root --make-pidfile --pidfile /home/manjesh/test.pid --exec /home/manjesh/simplescript.sh

simplescript.sh

   #!/bin/bash

   echo $(date)" SNMP Monitoring and Log aggregator service " >> /home/manjesh/log.txt


    while true
      do
      echo $(date) >> /home/dcae/snmp-service/log
      sleep 5
    done

When I execute the command it says "No such file or directory even if the file do exist"

Any help will be appreciated. Thanks.

Dave
  • 962
  • 5
  • 19
  • 44
  • Does the `/home/dcae/snmp-service` directory exist? – eddiem Nov 22 '16 at 20:42
  • Do all the scripts and directories you are using exist and have the proper permissions? – AlG Nov 22 '16 at 20:42
  • 1
    Which file does it say doesn't exist? Also, is `even if the file do exist` actually in the error message, or did you put the quotes wrong? – Barmar Nov 22 '16 at 21:36
  • The problem was I had created a file in Windows and moved to Ubuntu, and there was a formatting problem, http://stackoverflow.com/questions/14219092/bash-my-script-bin-bashm-bad-interpreter-no-such-file-or-directory – Dave Nov 23 '16 at 15:47

2 Answers2

1

The way I would do this is to use a cron job that triggers every minute and calls a script that writes the time every 5 seconds, like this:

Cron:

* * * * * /usr/local/bin/script >/dev/null 2>&1

Script:

#!/bin/bash
mkdir -p /home/dcae/snmp-service/
i="0"
while [ $i -lt 12 ]
do
echo $(date) >> /home/dcae/snmp-service/log
i=$[$i+1]
sleep 5
done
Jamil Said
  • 2,033
  • 3
  • 15
  • 18
0

The problem was I had created a file in Windows and moved to Ubuntu, and there was a formatting problem

-bash: ./my_script: /bin/bash^M: bad interpreter: No such file or directory

Community
  • 1
  • 1
Dave
  • 962
  • 5
  • 19
  • 44