Setting up crontab, still cant get it to work


 
Thread Tools Search this Thread
Operating Systems Linux Setting up crontab, still cant get it to work
# 1  
Old 04-14-2011
Setting up crontab, still cant get it to work

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:

Code:
tcpdump -s2000 -w'flowroute-%H%M.pcap' -G900 -W36 &

to run at 0800 Monday through Friday.

I have setup a crontab that reads:

Code:
0 8 * * 1,2,3,4,5 /root/crontab.txt

the text file I'm using to run the command just says:

Code:
#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:

Code:
tcpdump -s2000 -w'flowroute-\%H\%M.pcap' -G900 -W36

If any one has any suggestions or ideas for what i could do?
Currently this doesn't do any thing.
# 2  
Old 04-14-2011
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:

Code:
#!/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:
Code:
#!/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


Last edited by Corona688; 04-14-2011 at 08:57 PM..
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 04-15-2011
Thanks for the advice and help.

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


Code:
-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 ?

Thanks for your help
# 4  
Old 04-15-2011
Did it at least create /root/VoIPpackets ?

You omitted the most important line:

Code:
#!/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

Quote:
I'm not sure what to put for the path and user.
I'm not sure what it means to put a path or put a user.
Quote:
I use the root account. tcpdump is installed on the root.
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.
Quote:
I also save files to the root as well. What should I be using if not just /root ?
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.

Last edited by Corona688; 04-15-2011 at 07:42 PM..
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 04-15-2011
Thanks for your reply,

i think im just a little confused.

I will add in

Code:
. /etc/profile

What does this line do?
# 6  
Old 04-16-2011
Quote:
Originally Posted by Nasasdge
Thanks for your reply,

i think im just a little confused.

I will add in

Code:
. /etc/profile

What does this line do?
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.
Quote:
Originally Posted by Corona688
Also, cron's path is pretty minimal, way more than a users', so might not know where to find tcpdump. You can . /etc/profile to read in a more usual profile before you try and run things.
Also, I repeat my question. Did it at least create /root/VoIPpackets ?
This User Gave Thanks to Corona688 For This Post:
# 7  
Old 04-16-2011
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 Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Crontab] didn't work

Hello, Here is my crontab # Reboot one Sunday out of 2 at 02:00 0 2 * * 0/2 /usr/bin/reboot 2017-04-16 2017-04-23 2017-04-30 and so on I tested my crontab here, it seems to work Http://cron.schlitt.info/index.php?c...=100&test=Test However on my distrib linux mageďa When I register... (4 Replies)
Discussion started by: amazigh42
4 Replies

2. Shell Programming and Scripting

Crontab setting

Hi All, Can anyone tell me how to schedule the dbshell.sh script to run on sunday. I have scheduled as 1 19 7 * * /home/svr/dbshell.sh. kindly confirm confirm whether coded "7" or it should set to '0'. unix:$ crontab -l 0 19 6 * * /home/svr/dbemail.sh 1 19 7 * * /home/svr/dbshell.sh (2 Replies)
Discussion started by: arun888
2 Replies

3. UNIX for Dummies Questions & Answers

Crontab setting

Hi Team, Please help me to set one script in crontab. I have one script and inside script, its creating one log file for saving ouptut of script. i have to out that script in crontab. When i put the script in cronatab, it executed and log file created but no data in log. like this i put in... (3 Replies)
Discussion started by: shivshankar
3 Replies

4. Solaris

Crontab date setting problem

Hi, i wanted to schedule a backup script to run on 7.30pm every 1st Sat of month MAR, APR, SEP, OCT. Am i understanding it correctly? Because it doesn't seem to run according to the schedule i needed. = (7.30pm) & (1st to 7th day of the month) & (MAR, APR, SEP, OCT) & (Sat) 30 19 1-7... (1 Reply)
Discussion started by: beginningDBA
1 Replies

5. Solaris

Crontab date setting problem

Hi, 0 9 1,2,3,4,5,6,7 3,4 6 I want a cronjob to run on every 1st Sat of Mar & Apr. But the above schedule is running is running on the 1st 7 days. How do i rectify it? Thanks in advance. (2 Replies)
Discussion started by: beginningDBA
2 Replies

6. IP Networking

Setting to SSH home-PC from Work

Hello, My question is very basic for the settings to SSH my home PC from work. Home network two PC: Internet comes into my house through ISP modem and then the two PCs are connected with the router (Trendnet). The IPs for my PCs are How to set other stuffs for me to access my home PC from... (5 Replies)
Discussion started by: yifangt
5 Replies

7. Shell Programming and Scripting

Crontab setting error

Hi All, I have created crontab using following steps- 1) crontab -e (edited the file with) 0 10 * * 1-5 /home/user01/exercise/cron.sh 2) then saved this file with :wq 3) cron.sh contains the code- #!/bin/bash DAY=`date +%a` mkdir abc_${DAY} 4) done the execut permision... (3 Replies)
Discussion started by: pspriyanka
3 Replies

8. Shell Programming and Scripting

Setting crontab

Hey all, I would like to know how to set a cron job to run from 8:15 am to 4:00 pm? Or do I have to do this in 2 seperates cron? Thanks! (4 Replies)
Discussion started by: mpang_
4 Replies

9. Shell Programming and Scripting

Some env setting is causing the script not to work ?

Not sure what has changed in the Unix environment. The following script which was working is now not working. #!/usr/bin/ksh # ----------------------------------------------------------------------------- # File: monitor_db.sh # #... (1 Reply)
Discussion started by: uuser
1 Replies

10. UNIX for Dummies Questions & Answers

crontab -e dosent work

Hello! my crontab -e dosent work. Im getting this error message: sh: VI: not found The crontab files was not changed. How do i make it work? I think you should use "export editor=vi" or something. But i cant seem to get the correct line! pleas help... (11 Replies)
Discussion started by: dozy
11 Replies
Login or Register to Ask a Question