0

I have set up a cronjob on my server which is supposed to run every minute and store the output in the given file. I have been trying a lot and saw a lot of links but nothing seems to work. Following is the line which I wrote in crontab -e

* * * * * /root/snmp_codes/snmp/.\/snmpstats.py -f file -g > logfile.log

Can anyone please tell me what mistake I have made?

2
  • What's that \/ doing in the middle of the command? You should probably have either /root/snmp_codes/snmp/.snmpstats.py or /root/snmp_codes/snmp/snmpstats.py Apr 29, 2015 at 10:35
  • I gave chmod 775 snmpstats.py and while running the script normally I run it as ./snmpstats.py -f file -g. I used `\` as an escape sequence.
    – Vipul
    Apr 29, 2015 at 10:37

1 Answer 1

2

Fix the path so it's correct. Based on your comment it's likely to be /root/snmp_codes/snmp/snmpstats.py.

You can also modify the command so that it captures stderr as well as stdout like this (the 2>&1 attaches stderr to stdout so you get both written to the logfile.log):

* * * * * /root/snmp_codes/snmp/snmpstats.py -f file -g > logfile.log 2>&1
4
  • Can you tell me what is the meaning of 2>&1. I am a bit new to Linux so I don't know much.
    – Vipul
    Apr 29, 2015 at 10:48
  • It redirects stderr to the same place that stdout is currently being sent to.
    – cbz
    Apr 29, 2015 at 10:56
  • /root/snmp_codes/snmp/.\/snmpstats.py is equivalent to /root/snmp_codes/snmp/snmpstats.py\/ expands to / and /./ collapses to /. Apr 29, 2015 at 22:38
  • @Gilles Thanks. I wasn't sure enough that the `\` would be ignored rather than treated as a literal in the middle of a path, and didn't have a window to try it out on there and then. Hopefully catching stderr will lead the OP to their fault identification. Apr 29, 2015 at 22:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .