Commands to call script work from command line but not from Cron entry


 
Thread Tools Search this Thread
Operating Systems AIX Commands to call script work from command line but not from Cron entry
# 1  
Old 12-26-2013
Commands to call script work from command line but not from Cron entry

My first post evidently did not materialize so I posted it again:

Runnning a cron job every 5 mins to send data files to a state facility.
My original cron entry at worked fine:

Code:
01,06,11,16,21,26,31,36,41,46,51,56 * * * * /home/sftpuser/stateinoc-from-appname.ksh

Somewhere I have a problem picking up all the files so I wanted to capture all output from the script into a log file so I did this:

Code:
01,06,11,16,21,26,31,36,41,46,51,56 * * * * MYDT=`date +%m%d%Y%H%M`;/home/sftpuser/appname-from-appname.ksh 2>&1 |/usr/bin/tee -a /tmpmsql/import/appname/statesinoc/StateInoc.$MYDT.log

I am not sure if the entrie cron is failing or if just the log file isd not getting created. When I do it from the command line, the log file gets created and filled with my verbose output from the script.

Is there something special to do with my syntax in the cron entry ?


Thread: Commands to call script work from command line but not from Cron entry Edit Post

---------- Post updated at 04:46 PM ---------- Previous update was at 04:38 PM ----------

I don't know why I had the "tee" in there. Probably used it while I was testing. I have since taken it out:
Code:
01,06,11,16,21,26,31,36,41,46,51,56 * * * * MYDT=`date +%m%d%Y%H%M`;/home/sftpuser/flshots-from-cerner.ksh 2>&1>/tmpmsql/import/appname/statesinoc/StateInoc.$MYDT.log


Last edited by Skyybugg; 12-26-2013 at 05:41 PM.. Reason: Fixed CODE tags
# 2  
Old 12-26-2013
Usually 2-3 stumbling blocks get new cron users:
  1. There is no tty, no /dev/tty, no controlling terminal. You can create one in several ways, like ssh -tt and expect, but usually one does not want terminal output from a cron job.
  2. You have to build the environment manually, and if you were not careful writing your ~/.profile, it may want a tty. Without the usual PATH, LD_LIBRARY_PATH, etc. many apps fail.
  3. Execuatble scripts should be set up according to man exec to run under the right interpreter. Cron will call scripts using sh, and if you lack exec permissions or first line is not:
    Code:
    #!/full/path/to/interpreter [ <optional-one-argument> ]

    then you are in trouble.
I often test run cron script lines using something like:
Code:
$ echo '<your-command-line>' | ssh localhost sh

(no terminal, called from sh).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Cron entry to pass the value to script

0 I have a script(main.sh) which calls another script(Get_Files.sh) and gets a value in a variable like the below: File_to_Refresh="$(sh /Aug/work/Get_Files.sh /Aug/Work/Universal_File.txt)" Now I have to schedule the script main.sh for 3 different files i.e. the Universal_File.txt with 3... (2 Replies)
Discussion started by: bhartiya007
2 Replies

2. Shell Programming and Scripting

awk script to call another script based on second column entry

Hi I have a text file (Input.txt) with two column entries separated by tab as given below: aaa str1 bbb str2 cccccc str3 dddd str4 eee str3 ssss str2 sdf str3 hhh str1 fff str2 ccc str3 ..... ..... ..... (1 Reply)
Discussion started by: my_Perl
1 Replies

3. Shell Programming and Scripting

Script runs in command-line fine but times out in CRON?

Hi, I have a script that seems to run to completion when in the command-line, but when it is run using the cron, it seems to time out. They both start and run fine, but on the CRON it stops prematurely. The script hits an API every few seconds and grabs data. Does anyone have any idea on... (4 Replies)
Discussion started by: phpchick
4 Replies

4. Shell Programming and Scripting

Commenting out a cron entry through a shell script

In my cron thare is a line like 24 11 * * * /usr/batch/bin/abc.sh > /usr/batch/log/abc.log 2>&1 along with other entries. I want to comment out this line through a shell script. My local variable 'line'ontains the full entry (i.e. 24 11 * * * /usr/batch/bin/abc.sh > /usr/batch/log/abc.log... (4 Replies)
Discussion started by: Soham
4 Replies

5. Shell Programming and Scripting

How to check if script is run via cron or manual=command line?

Hi all, I have a script that can be run via cron or via the command line. Is there any way that I can place something on the script to be able to distinguish/differentiate whether the script was run via a user in the command line or whether it was run from the cron? (3 Replies)
Discussion started by: newbie_01
3 Replies

6. Shell Programming and Scripting

CRON shell script only runs correctly on command line

Hi, I'm new to these forums, and I'm hoping that someone can solve this problem... To make things short: I have DD-wrt set up on a router. I'm trying to run a script in CRON that fetches the daily password from my database using SSH. CRON is set like so(in web interface): * * * *... (4 Replies)
Discussion started by: louieaw
4 Replies

7. UNIX for Dummies Questions & Answers

Script through cron and command line

I have a script which runs fine through command line, but doesn't run through cron. There are some variables which are set by the .profile file which are used by the script. Is it that cront does not pick these variables. $/export/home/rahul/bin/createfile.sh >>... (3 Replies)
Discussion started by: rahulrathod
3 Replies

8. UNIX for Dummies Questions & Answers

script works on command line, not in cron job

Hey there, I'm a total newbie unix guy here and just picking this stuff up. Have a very small script I put together that works fine from the command line but not once I put it in a cron job. Searched and found this thread and am wondering it it has something to do with setting variables, though the... (7 Replies)
Discussion started by: JackTheTripper
7 Replies

9. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies

10. Shell Programming and Scripting

command line work script doesn't

Hello, I'm stuck and confused as to why when I execute things form the command line it works but when in a script it doesn't. My script: ### creating a lock on the console touch /var/run/console.lock chmod 600 /var/run/console.lock echo "$User" >>... (2 Replies)
Discussion started by: larry
2 Replies
Login or Register to Ask a Question