Script only runs first time through crontab


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Script only runs first time through crontab
# 1  
Old 10-25-2016
Script only runs first time through crontab

Hello,

I am trying to run a script through crontab and it runs the first time and then it does not run.

I tried to run a simple script (as shown below) and I see the same issue.

Code:
#!/bin/ksh
clear
echo "Good Morning, World." > /tmp/test123

Crontab Entry:

Code:
30 09 * * * /home/uhosting/test > /tmp/test123 2>&1

Any advise/comments, please?
# 2  
Old 10-25-2016
  1. Before the /tmp... use >> instead of >
  2. If you schedule it once per day (at 9:30) then it is normal that is only run once per day Smilie
  3. Avoid to name a script "test" : "test" already is the name of a unix command ... (as well as "script" by the way ! )
  4. Don't use the same logfile inside your script and from crontab (conflicting redundancy by concurrent access )

Last edited by rbatte1; 10-26-2016 at 10:24 AM.. Reason: Converted to formatted number-list
# 3  
Old 10-25-2016
In the script or in the crontab?
# 4  
Old 10-25-2016
Quote:
Originally Posted by hasn318
In the script or in the crontab?
In the crontab. And get rid of the one in the script!

Andrew
# 5  
Old 10-25-2016
Up to you, but avoid to update them both at the same time (i updated my previous post).
# 6  
Old 10-25-2016
Thanks for the inputs, that works. Now the script that I have issue, I am trying to logon to a remote server and get a listing from a directory.

Code:
ssh -q servername 'ls -al /nim/dr/mksysb/*|grep _dr|cut -c37-90|cut -d" " -f2-8|cut -d_ -f1' > /tmp/output

the above command works fine from the command line but not through crontab
# 7  
Old 10-25-2016
Quote:
Originally Posted by hasn318
Thanks for the inputs, that works. Now the script that I have issue, I am trying to logon to a remote server and get a listing from a directory.

Code:
ssh -q servername 'ls -al /nim/dr/mksysb/*|grep _dr|cut -c37-90|cut -d" " -f2-8|cut -d_ -f1' > /tmp/output

the above command works fine from the command line but not through crontab
At this point I'm guessing ssh keys. You probably need to explicitly include the private key file you are using:
Code:
ssh -q -i /home/myname/.ssh/id_dsa ...

assuming the identity file is the id_dsa file.

What are you trying to get from the server? Do you have stat on the server? Could you use that to find the file information you are looking for?

Andrew
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to convert this script so that it runs the dbv at most 5x at a time instead of serially?

Hi, Attached is a generated script of the database files if/when we want to run dbv = dbverify. The script runs fine by itself but it does take awhile to finish. In a worse case scenario, it can take up to 7 hours to finish as the dbv runs serially. I need help and guidance to somehow... (5 Replies)
Discussion started by: newbie_01
5 Replies

2. Shell Programming and Scripting

Job runs manually, doesn't work in crontab

I have a script (/home/admin/run_bkup.sh) that I can run manually to kick off an executable job. I want to run it in crontab, but it doesn't work. Here's the script: shell=/bin/bash today=$(date +"%m-%d-%y") /opt/CPsuite-R77/fw1/bin/upgrade_tools/upgrade_export mgt-svr-bkup-$today << EOF y... (18 Replies)
Discussion started by: df08388
18 Replies

3. UNIX for Dummies Questions & Answers

Script runs manually but not from crontab in UNIX

Hi Guys, I am executing the script called Delet.sh manually it is successfully completing the task but it is failing to run vi cron tab, I tried to pass PATH & .profile before execution but no luck, Any suggestions? Script below #!/usr/bin/ksh #set -x # Purpose : Delete folders file from... (9 Replies)
Discussion started by: Anilsa77
9 Replies

4. Shell Programming and Scripting

Script runs good manually but failing via crontab

Hello Gurus, I have written small script which will start the given service if its stop .Its running fine when manually executed but its unable to run from crontab. #!/bin/bash SERVICENAME=rsyslog service $SERVICENAME status > /dev/null SYSLOGSTATUS=`echo $?` COUNT=0 THRESHOLD=3 if ... (4 Replies)
Discussion started by: kapil514
4 Replies

5. Shell Programming and Scripting

Script taking more time in CRONTAB

Hello All, I have created a shell script, When i run it manually as ./<script_name> it takes 5 hours to run, but when i am scheduling it in crontab, it is taking 20 hours to run. Please help me and advice, what can be done to reduce the time in crontab. Thank you (6 Replies)
Discussion started by: anand2308
6 Replies

6. Shell Programming and Scripting

Part of the Shell script is not running via crontab, runs fine manually

Hello Team, As a part of my job we have made a script to automate a service to restart frequently. Script having two functions when executing it's should find the existing service and kill it, then start the same service . Verified the script it's working fine when executing... (18 Replies)
Discussion started by: gowthamakanthan
18 Replies

7. Shell Programming and Scripting

Script runs fine manually but not in crontab

Hello Guys, I have scratched my head alot on this but couldn't find clue what's wrong. Can you please help me with this? My problem is as following. 1) When I manually execute following script it runs successfully with below output. bash-3.00# more smssend #!/bin/bash echo -e "<Request... (16 Replies)
Discussion started by: umarsatti
16 Replies

8. Shell Programming and Scripting

Script runs manually but not correctly from crontab

Hello all, I'm new here and have a question if you don't mind helping me. I have a script that will work if I kick if off manually but not from Cron. My cron entry is this: 05,20,35,50 * * * * /scripts/status.sh > /dev/null 2>&1 The first script (works fine) is this: #!/bin/sh # #... (14 Replies)
Discussion started by: hs3082
14 Replies

9. Shell Programming and Scripting

Script runs manually but not correctly from crontab

Hi all I have this inside a shell script (bash): cd DIRECTORY find . -maxdepth 1 | sed 's#./##' | /usr/bin/xargs -I '{}' chown -Rv '{}' /DIRECTORY/'{}' All the directories in this location are named after usernames, so it simply sets the owner to that of the username of the folder. It... (5 Replies)
Discussion started by: fakesy
5 Replies

10. Shell Programming and Scripting

crontab runs only one line in iterated program

I have a crontab as below: PATH=/usr/local/sbin:/bin/:..... etc etc 0 8 * * * /home/user/jobs/poll.sh 2>/dev/null 1>/dev/null Now the script poll.sh is called at correct time and executes. This is how poll.sh looks like #!/bin/bash... (2 Replies)
Discussion started by: chakrapani
2 Replies
Login or Register to Ask a Question