Cronjob script not renaming file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cronjob script not renaming file
# 1  
Old 04-28-2015
Cronjob script not renaming file

Hello,
I have below script, which connects to ftp server, pull a file and then it renames it after deleting previous day file. This was working before but now it is not able to rename 'Red_bill.txt' to `Red_bill.V01.txt`. If I run manually 'rename Red_bill.txt Red_bill.V01.txt', I am able to rename, but script is not able to do so. Is something wrong or changed on below script ? Can somebody have a look and help ?

Code:
tpvwex@vmtpr01:~> cat /home/vendors2/tpvwex_home/pull_file_wrightexpress.sh
#!/bin/sh
HOST='ftp.trigertpv.com'
USER='Red'
FILE='Red_bill.txt'
cat > /tmp/script_file_$$ <<EOF
    get ${FILE}
    rm Red_bill.V01.txt
    rename ${FILE} Red_bill.V01.txt
    exit
EOF
 sftp -b /tmp/script_file_$$ $USER@$HOST
exit_status=$?
rm -f /tmp/script_file_$$
if [ $exit_status != 0 ];then
   echo "SFTP file transfer is failed for file $FILE" |mailx -s "FTPtrigertpv status"  BSS_C8@Red.com
else
echo "SFTP file transfer is successfull for file $FILE" |mailx -s "FTPtrigertpv status" BSS_C8@Red.com
cp $FILE $FILE.`date +%m%d%y`
fi
tpvwex@vmtpr01:~>

# 2  
Old 04-29-2015
I would think you might need a cd before you call sftp to be sure that cron is running your script in the directory where the file to be transferred is located.

Is it the rename that is failing? Or, could it be that the file is not found to copy or that you don't have permission to remove the remote file that you are replacing?

Assuming that when your script is run by cron, the file you're moving to the remote host is available; does the sftp command:
Code:
    get ${FILE} Red_bill.V01.txt

give you the same errors as the commands:
Code:
    get ${FILE}
    rm Red_bill.V01.txt
    rename ${FILE} Red_bill.V01.txt

# 3  
Old 04-29-2015
I login to server with tpvwex and did a manual sftp to ftp server. From there, I am able to run 'rename Red_bill.txt Red_bill.V01.txt' (without doing cd).
My main objective here is, to rename Red_bill.txt to Red_bill.V01.txt. Next day, new Red_bill.txt should come at ftp server and cronjob should be able to pull it again. Now it is not renaming it, so cronjob is pulling same file again.
If I replace those 3 lines and add one which you suggested, I am able to fetch file as Red_bill.V01.txt, but at ftp server, it was not renamed. It is still Red_bill.txt
# 4  
Old 04-29-2015
Am I missing something here?

On ftp server :
- New "Red_bill.txt" should be over-written hopefully if permissions allowed.
- If not, you should be having the same old file (check with timestamp) on the server

If you saying your cron will always pull the old file, which means you having same file again and ultimately means the upload at the other end didnt work. Could you please check.

Also, you can always debug it with sftp -v[vv]
# 5  
Old 04-29-2015
On ftp server, I am able to rename Red_bill.txt to Red_bill.V01.txt with same user, so permission should not be an issue.
Cronjob is always pulling Red_bill.txt, which it is supposed to. But cronjob is also supposed to rename is to Red_bill.V01 so that there should be no more Red_bill.txt.
Now, since Red_bill.txt is already exists, cronjob is pulling same file next day also. Ideally, if Red_bill.txt is not there (because it was already renamed to Red_bill.V01.txt yesterday), cronjob should not pull any file.
# 6  
Old 04-30-2015
Ok.
I was able to fix this. I put a prefix - like below
Code:
get ${FILE}
    -rm Red_bill.V01.txt
    -rename ${FILE} Red_bill.V01.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Linux script for several cronjob

I have a linux server for my joomla website. I am importing xml feeds (around 200). The component give a tool which list all the cron job commands to automaticaly make the feeds import I don't want to add one by one each cron job. So my idea is to make one cron job which will call a shell... (0 Replies)
Discussion started by: nino59
0 Replies

2. Shell Programming and Scripting

Shell script with cronjob

Hello All, I have a script which will cd into a directory based on current timestamp. It will then do a grep and search for a condition. It's run on a cron job that runs every 30 minutes. So if it finds a match in 00, it sends out the contents of that grep to an alert and emails out. Now... (3 Replies)
Discussion started by: liketheshell
3 Replies

3. UNIX for Dummies Questions & Answers

How to Update DB table from txt file using CRONJOB in Unix Shell Script

Hi Experts, can guide how we can Update a Database Table using a txt file source Using Unix Shell Scripts. What are the Cron Jobs codes can written to Update DB table. txt file contains record like data. US 09/03/2012 User DocType DocID. these above feilds in txt files need to be updated in... (4 Replies)
Discussion started by: mahesh.sap
4 Replies

4. AIX

SH Script Execution Problems with Cronjob

Hi, I have created a sh script to startup and shutdown the oracle database, when I execute the script thru command line it execute successfully, but when I call the script thru cronjob it does not execute. The scripts are as follows: LOG=/oracle/times.log export ORACLE_SID=prod echo... (6 Replies)
Discussion started by: lodhi1978
6 Replies

5. UNIX for Dummies Questions & Answers

Script not running through Cronjob

Hi, I have a .ksh script which updates the database. The script is running fine manually but it is not running through cron.All the file permissions are fine. The script contents are as below: #!/usr/bin/ksh ddate=`date +%Y%m%d` echo $ddate nohup sqlplus crm/crm @db_state_sync.sql >>... (3 Replies)
Discussion started by: shivangi
3 Replies

6. UNIX for Dummies Questions & Answers

how to cancel a cronjob if the cronjob still running

hi everyone I'm newbie in this forum hope I can get some help here :) I have a command in crontab that executed every 1 minute sometime this command need more than 1 minute to finish the problem is, the crontab execute this command although it's not finish processing yet and causing the system... (7 Replies)
Discussion started by: 2j4h
7 Replies

7. Shell Programming and Scripting

Renaming file names in a shell script

I want to write a shell script that will rename all the file names to today's date attached to it.. so for example i have a file names like file1.sales.20081201.txt.c zbrs.salestxtn.20091101.txt.inn then it will rename both the files with todays date to it so the file names get changed... (1 Reply)
Discussion started by: rudoraj
1 Replies

8. Solaris

Creating a CronJob Script

Hi All, Good Day. Anyone can guide me on how to create a cronjob script that run prstat -a and vmstat 10 10 on the certain time of the day and produce a log which will be kept in a specific directory? I am running on Solaris 10. Thanks. (2 Replies)
Discussion started by: ronny_nch
2 Replies

9. Shell Programming and Scripting

cronjob inside the script

Hiii, can nayone provide me the sample script which can do the following tasks--- I will apperciate if anyone give me their valuable inputs.I guess this is not at all a big task for the experts in the forum so kindly help me out in this. (3 Replies)
Discussion started by: namishtiwari
3 Replies

10. Shell Programming and Scripting

help help cronjob problem with script

hi all, have no experience with cronjob at solaris, i have create script like below: #!/bin/sh DAY=`/export/home/oracle/bin/lastdate | nawk '{print $1}'` /export/home/orahome/bin/sqlplus -s abc/abc<<eof set heading off; set linesize 100; set feedback off; spool... (4 Replies)
Discussion started by: bucci
4 Replies
Login or Register to Ask a Question