OK I have been working on this simple action for a while and I cannot get it to work.
First off im new to the linux command line world. I feel like I am missing something simple.
What I am trying to achieve is that I want this command:
the text file I'm using to run the command just says:
#captures packets in 15min segments and stops after 36 segments
#cronjob is setup for starting at 800 and then would go until 1700
tcpdump -s2000 -w'flowroute-%H%M.pcap' -G900 -W36
I have set the txt as an executable. Im running this from the root.
I have also try adding in an escape character breaks to compensate for the % symbol
what i mean:
The crontab entry looks okay, but there's lots wrong with your script.
Technically the name doesn't matter but shell scripts are usually .sh, not .txt. It being named .txt makes me wonder if you set it executable -- if it's not, cron can't run it. chmod +x crontab.sh
The first line in any shell script should be a #! line telling it what shell to use, like this:
#!/bin/sh
Also, cron's path is pretty minimal, way more than a users', so might not know where to find tcpdump. You can [icode]. /etc/profile[icode] to read in a more usual profile before you try and run things.
You're missing a space between -w and the filename. You should also tell it exactly where to put them since cron may run things where you expect it to.
Having a script still running for hours on end may prevent root's crontab from running anything else during that time. If you put the command into the background, the shell will return immediately and cron won't have to wait for it. (If it hangs, cron will end up creating one more hanging tcpdump process per day, heh.)
So:
#!/bin/sh
. /etc/profile
# just to prove this script's running at all
touch /root/cronranme
#captures packets in 15min segments and stops after 36 segments
#cronjob is setup for starting at 800 and then would go until 1700
#
# Some shells don't have "disown", you can just lop that off if yours doesn't.
nohup tcpdump -s2000 -w '/root/flowroute-%H%M.pcap' -G900 -W36 & disown
I have set the script
voippackets.sh ( i just renamed the file as such)
I double checked the permissions and they are set as an executable.
I rewrote the code as per your example
-bash-3.00# cat voippackets.sh
#!/bin/bash
#just to prove this script's running at all
touch /root/VoIPpackets
#capture packets in 15 min segments and stops after 36 segments
nohup tcpdump -s2000 -w '/root/flowroute-%H%M.pcap' -G900 -W36 & disown
I'm not sure what to put for the path and user. I use the root account. tcpdump is installed on the root. I also save files to the root as well.
What should I be using if not just
/root ?
#!/bin/sh
. /etc/profile
# just to prove this script's running at all
touch /root/cronranme
#captures packets in 15min segments and stops after 36 segments
#cronjob is setup for starting at 800 and then would go until 1700
#
# Some shells don't have "disown", you can just lop that off if yours doesn't.
nohup tcpdump -s2000 -w '/root/flowroute-%H%M.pcap' -G900 -W36 & disown
I'm not sure what it means to put a path or put a user.
What do you mean by "installed on the root"? tcpdump is installed inside /root? If you've put tcpdump anywhere funny, you should run it with an absolute path like /path/to/tcpdump -s2000 ... Otherwise it will have no idea where to look for it.
You can save them wherever you want. The system can't stop you because you're root. Running as root may be unavoidable if you need to run tcpdump. In short, /root will work.
Run all the lines in /etc/profile and include any variables from it into your shell. Unlike a shell login, crontab does not do this by default, you have to do it yourself.
Also, I repeat my question. Did it at least create /root/VoIPpackets ?
I setup the new cron on friday and didnt do any testing on it yet. I will know more on Monday. Thanks for your help. I will let you know if it works for me or not
I can in today, I didnt come into the office on tuesday, I found that the changes that I made to the cron and the script on monday have made it work,
YAY!