Script works but doesn't with cron


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script works but doesn't with cron
# 1  
Old 02-01-2010
Question Script works but doesn't with cron

Good morning,

The script below without the hilited text successfully FTPs the files in question to the other server when it is called from the crontab. I don't want to establish an FTP connection when there are no files so I tried including the hilited lines to only establish an FTP connection if there is a file to ftp. When I included those three lines, the crontab doesn't do the FTP, it renames the file to append the timestamp, but does not FTP the file. If I run this script including the hilited lines manually, the FTP works when there is a file, and correctly is ignored when there isn't one.

Can anyone here make sense of this? How can I get it to work when called from the cron job?

Code:
echo `date` MoveJob Starts
for testfile in /SYSRES/SYSREX/XPOLLD*0001
do
  if [ -f $testfile ]
  then
        mv $testfile $testfile.ftp
  fi
done
if [ -f *.ftp ]
then
ftp -v -n -i <ip address> << cmd
user "user" "password"
cd /PollData/Uploads
lcd /SYSRES/SYSREX
mput *.ftp
quit
cmd
fi
for testfile in /SYSRES/SYSREX/XPOLLD*0001.ftp
do
  if [ -f $testfile ]
  then
        cp $testfile `dirname $testfile`/`basename $testfile .ftp`.`date '+%m%d%H%M%S'`
        rm $testfile
  fi
done
echo `date` MoveJob Ends

Note: this is on an AIX server.

Last edited by philplasma; 02-01-2010 at 11:50 AM..
# 2  
Old 02-01-2010
Older version of ksh/bash shells dont support wildcard. ( I think bash above v 3 will do that).
if you really want to check then you can count the files and if OK, proceed further.

Code:
files=$(ls *.ftp 2> /dev/null | wc -l)
if [ "${files}" -eq "5" ]; then  ## for 5 files
 .....

# 3  
Old 02-01-2010
The quick fix would be:
cd /SYSRES/SYSREX
if [ -f *.ftp ]

The "lcd" in the "ftp" commands is then not needed.
# 4  
Old 02-01-2010
PHP

I tried your (anchal's) suggestion and got the same result. Fail to FTP when called from cron, succeed to FTP when run from shell. Succeed to rename file in both cases. methyl's suggestion looks good and cleans up my script as the script is already in that directory, but it still doesn't work - fails to FTP when called from cron, succeeds to FTP when run from shell. Could there be a permissions problem where cron can't ftp?

Last edited by philplasma; 02-01-2010 at 12:11 PM..
# 5  
Old 02-01-2010
When in cron make no assumptions.
It's worth making a one-off cron which just contains a unix shell "set" command and studying the output.
# 6  
Old 02-02-2010
Hi philplasma

If am reading correct

The following code will check for the file in the home path of the user where the cron is set.


Code:
if [ -f *.ftp ]

I think your *.ftp files were in other dir other than cron user home path.

Regards
GIC
# 7  
Old 02-08-2010
MySQL

GIC1986, Yes! That was exactly it. Thanks, I had to change the test condition to include the full path even though the script that cron was running was already in that path.

Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

PING to AIX works but TELNET FTP SSH doesn't work

root@PRD /> rsh DR KFAFH_DR: protocol failure due to unexpected closure from server end root@PRD /> telnet DR Trying... Connected to DR. Escape character is '^]'. Connection closed. root@PRD /> ftp DR Connected to KFAFH_DR. 421 Service not available, remote server has closed connection... (2 Replies)
Discussion started by: filosophizer
2 Replies

2. Shell Programming and Scripting

SSh works but sftp doesn't for all users except root

I am sorry if i post in wrong Form. i have AIX server in which ssh works for all users but sftp only works for root user . it is too much important for me to solve this . Your help will be greatly appreciated. (1 Reply)
Discussion started by: khalid khanAIB
1 Replies

3. UNIX for Dummies Questions & Answers

Execution problem with Cron: Script works manually but not w/Cron. Why?

Hello gurus, I am making what I think is a simple db2 call from within a shell script but I am having difficulty producing the desired report when I run the script shown below from a shell script in cron. For example, my script and the crontab file setup is shown below: #!/bin/ksh db2... (3 Replies)
Discussion started by: okonita
3 Replies

4. Shell Programming and Scripting

Calling bash script works when called manually but not via Cron?

Hi, I've got a Bash backup script I'm trying to run on a directory via a cron job nightly. If I ssh in and run the script manually it works flawlessly. If I set up the cron to run evertything is totally messed up I don't even know where to begin. Basically the path structure is ... (6 Replies)
Discussion started by: wyclef
6 Replies

5. Solaris

Drop_caches doesn't work on Solaris but works on RHEL6

Hello Experts, I am performing performance tests on a few mysql select queries. I use the following command to clear the memory disk caches. sync && echo 3 | sudo tee /proc/sys/vm/drop_caches I however see that the above command works on RHEL6 but doesn't work on Solaris 10. I asked... (4 Replies)
Discussion started by: Anirudh Kumar
4 Replies

6. Shell Programming and Scripting

Expect_out(buffer) works but it doesn't get all lines

Hello "expect" experts I am new at Expect. I have searched for a little while how to capture multiple lines with Expect and I am almost succeeded on that but I don't get all the lines of a command's output that the script executes on a server. Here is how my script works in a nutshell - ... (6 Replies)
Discussion started by: capacho6666
6 Replies

7. Red Hat

Samba 3.0.33 (sorta) works, 3.5.4 doesn't

I'm trying to get a RHEL 5.4 base system to authenticate against a W2K8 domain With the stock samba-3.0.33, I can use wbinfo and getent just fine, but I cannot actually authenticate. Googling finally led to a bug that strongly suggests that 3.0.33 cannot and will never be able to ... (1 Reply)
Discussion started by: jnojr
1 Replies

8. Shell Programming and Scripting

Script works but doesn't?

Hi everyone I'm new here so and I'm just starting to learn a bit of Solaris and I'm working on repairing 10 year old scripts for our system here at work. When I execute the commands at my prompt everything go's through smooth. I'm using gedit to edit my code because I'm still getting used to the... (4 Replies)
Discussion started by: 82280zx
4 Replies

9. Shell Programming and Scripting

Script doesn't work as expected when run on cron

The script checks for free space stats on Oracle. If there are any tablespaces with more than 85% usage it prints the details of the tablespace. If all the tablespaces have more than 15% free space, then "All tablespaces have more than 15 pct free space" must be printed on the screen. When I run... (2 Replies)
Discussion started by: RoshniMehta
2 Replies

10. 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
Login or Register to Ask a Question