Cd and mv in a tar ksh script not working


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Cd and mv in a tar ksh script not working
# 1  
Old 06-02-2015
Cd and mv in a tar ksh script not working

hi forums, can you help me on how to make cd and mv code work in this script?
Code:
#!/bin/ksh
#i got it from: How to tar, compress and remove files older than two days
MAIN_DIR=/home/user/pumela
find ${MAIN_DIR} *.txt -mtime -3> FILE_LIST
tar -cvf archive1.tar -L FILE_LIST
for x in ${FILE_LIST}
rm  $x
rm FILE_LIST
done
cd /home/user/pumela #this code not working
mv *.tar ./archive #this code not working also

# 2  
Old 06-02-2015
You haven't told us what operating system you're using, but your tar command probably only works on AIX systems. (At least it won't work on Solaris-, Linux-, or BSD-based systems.) What operating system are you using?

What makes you think something is wrong with cd and mv in your script when:
  • your find utility is looking for files less than three days old instead of more than two days old,
  • your find command is subject to argument list too long errors if there are lots of *.csv files, and
  • your for loop has a syntax error?
# 3  
Old 06-02-2015
Quote:
Originally Posted by Don Cragun
You haven't told us what operating system you're using, but your tar command probably only works on AIX systems. (At least it won't work on Solaris-, Linux-, or BSD-based systems.) What operating system are you using? IBM AIX OS, sorry i said windows in my prev. topic


What makes you think something is wrong with cd and mv in your script when:
  • your find utility is looking for files less than three days old instead of more than two days old, - yep bec. of the -mtime and -3
  • your find command is subject to argument list too long errors if there are lots of *.csv files, and
  • your for loop has a syntax error?i cannot determine its root cause
# 4  
Old 06-02-2015
Hi,

you can try like

Code:
#!/bin/ksh

MAIN_DIR=/home/user/pumela
FILE_LIST=/home/user/file_list.txt
find ${MAIN_DIR} -type f -name "*.txt" -mtime +2 > ${FILE_LIST}
tar -cvf /full/path/archive1.tar $(cat ${FILE_LIST})
for x in $(cat ${FILE_LIST})
do
rm $x
done
rm ${FILE_LIST}
mv /full/path/archive1.tar /full/path/to/destination/
exit;

# 5  
Old 06-02-2015
Quote:
Originally Posted by venky.b5
Hi,

you can try like

Code:
#!/bin/ksh
 
MAIN_DIR=/home/user/pumela
FILE_LIST=/home/user/file_list.txt
find ${MAIN_DIR} -type f -name "*.txt" -mtime +2 > ${FILE_LIST}
tar -cvf /full/path/archive1.tar $(cat ${FILE_LIST})
for x in $(cat ${FILE_LIST})
do
rm $x
done
rm ${FILE_LIST}
mv /full/path/archive1.tar /full/path/to/destination/
exit;

I modifie the code according to your specifications:
Code:
#!/bin/ksh
MAIN_DIR=/home/user/pumela/
FILE_LIST=/home/user/pumela/file_list.txt
find ${MAIN_DIR} -type f -name "*.txt" -mtime +2 > ${FILE_LIST}
tar -cvf /home/user/pumela/archive1.tar $(cat ${FILE_LIST})
for x in $(cat ${FILE_LIST})
do
rm $x
done
rm ${FILE_LIST}
mv /home/user/pumela/archive1.tar /home/user/pumela/archive
exit;

i executed it but i got no luck on mv to archive:
Code:
pumela@vampyrtest Non Production
/home/user/pumela bash pumelatar.ksh
pumelatar.ksh: line 2: $'\r': command not found
find: bad status-- /home/user/pumela/
cat: cannot open /home/user/pumela/file_list.txt
: No such file or directory
pumelatar.ksh: line 8: syntax error near unexpected token `$'do\r''
'umelatar.ksh: line 8: `do
pumela@vampyrtest Non Production
/home/user/pumela

# 6  
Old 06-02-2015
Code:
pumelatar.ksh: line 2: $'\r': command not found

Windows detected ;-) Use vi, Luke! Write your script on UNIX or use an editor which understands the difference between Windows and UNIX.
# 7  
Old 06-02-2015
Quote:
Originally Posted by agent.kgb
Code:
pumelatar.ksh: line 2: $'\r': command not found

Windows detected ;-) Use vi, Luke! Write your script on UNIX or use an editor which understands the difference between Windows and UNIX.
what? i completely didn't catch up what you had said here. i used putty, telnet and cygwin but i don't know vi. Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

TAR exclude is not working !

I have solaris 10 and my following exclude is not working: tar -cvf /export/home/backups/$audit-Data-$useday.bkup.tar /Data --exclude=/Data/ssg/output a /Data/ssg/output/ 0K a /Data/ssg/output/ssg-ported508.txt 107142K a /Data/ssg/output/ssg-ported747.txt 1801K a... (4 Replies)
Discussion started by: mrn6430
4 Replies

2. Red Hat

Linux ksh script not working in crontab

I am Not sure why following script is not capturing the counts only when using crontab !! when I run it fromt he command line it is fine ! what is missing here ! #!/usr/bin/ksh host=`uname -n` tdate=`date` userid='dbid/password' totalevents=`sqlplus -s $userid << - set timing off ... (1 Reply)
Discussion started by: mrn6430
1 Replies

3. Shell Programming and Scripting

Script not working with ksh

Hi I am not able to execute a script with ksh. Its not giving any error too. I have tried with absolute path /usr/bin/ksh test.sh . Also checked path variable and all looks fine It runs fine with sh. OS is solaris 10. (9 Replies)
Discussion started by: ningy
9 Replies

4. Shell Programming and Scripting

sed command not working inside ksh script but works fine outside

Hi, I am a bit confused ,why would a sed command work fine outside of ksh script but not inside. e.g I want to replace all the characters which end with a value and have space at end of it. so my command for it is : sed -i "s/$SEPARATOR /$SEPARATOR/g" file_name This is working fine in... (8 Replies)
Discussion started by: vital_parsley
8 Replies

5. Shell Programming and Scripting

ksh script not working

Here's the script: #!/usr/bin/ksh Date=`date +%m%d%y` CDate=`date` FileName=cintas_hosts_and_users.$Date echo $CDate >> $FileName #echo $FileName for host in `cat /collect/itthomp/cintas_hostnames.dat` do echo $host >> $FileName ssh $host "awk -v Fname=$FileName -F: '{if($1 != "root"... (3 Replies)
Discussion started by: jgt157
3 Replies

6. Shell Programming and Scripting

KSH script Not working (calculate days since 1/1/2000 given day 4444)

I am unable to get this KSH script to work. Can someone help. I've been told this should work with KSH93. Which I think I have on Solaris 10. If I do a grep -i version /usr/dt/bin/dtksh I get @(#)Version M-12/28/93d @(#)Version 12/28/93 @(#)Version M-12/28/93 This is correct for... (5 Replies)
Discussion started by: thibodc
5 Replies

7. Shell Programming and Scripting

ksh script not working if triggered by scheduler

I have a script that works well if i execute manually using informix user. However, it does not execute properly if triggered using the scheduler (ESP). This is the partial part where it doesn't work. i added some tracing but i can't figure it out. #!/bin/ksh let db_is_up=0... (6 Replies)
Discussion started by: tungaw2004
6 Replies

8. UNIX for Dummies Questions & Answers

tar not working in HP unix

Hi , I want to tar a directory and then ZIP it. I am using HP unix. I want to tar the directory such that the original directory should be there . When i tried to use tar -cvf . My system is showing error (>) tar -cvf test_per tar: usage tar {txruc}] file] ... (>) tar -c... (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

9. Shell Programming and Scripting

host cp in ksh script not working

The following script is designed to backup the oracle control file to the trace directory and then copy (the trace file that was created by the backup command) and rename that file(to a .sql) to a backup disk. When I run the script from sqlplus as sysdba everything works but when I execute from... (1 Reply)
Discussion started by: tparker123
1 Replies

10. UNIX for Advanced & Expert Users

formatting textfile inside ksh script using awk not working

I cannot seem to get this text file to format. Its as if the awk statement is being treated as a simple cat command. I manned awk and it was very confusing. I viewed previous posts on this board and I got the same results as with the the awk command statement shown here. Please help. ... (6 Replies)
Discussion started by: tekline
6 Replies
Login or Register to Ask a Question