![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| recovering files removed with rm | jack1981 | UNIX for Dummies Questions & Answers | 4 | 09-15-2006 04:06 AM |
| setfacl -x doesn't shows it removed the ACL | braindrain | Shell Programming and Scripting | 0 | 08-01-2006 02:09 AM |
| Will Old Files Be Removed | sunsation | UNIX for Dummies Questions & Answers | 5 | 06-26-2005 09:24 PM |
| i have removed my email address | K-ONE | Post Here to Contact Site Administrators and Moderators | 1 | 04-10-2005 05:45 AM |
| removed cdroms still appear mounted | DarkLord | UNIX for Dummies Questions & Answers | 1 | 01-15-2003 11:55 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
directories are not getting removed
hello Everyone.
I’m having the following problem: I have number of installation in the directory. each installation consists of executable file and directory. when I do the new installation I move old one to File_name-Time_stamp. this is done for executable and for directory. Everything is done by shell script and works just fine. Now I want to get rid of old installations and keep only new one and last back up (which is created just before ) this script is working fine except one thing - it does not remove the directory. if I do the same manually - it works just fine, however inside the script it doesn’t. Does anyone can help me and explain to me what’s wrong in my script? Thanks a lot in advance! below is my script: #!/bin/ksh #cleanup.ksh typeset SYS_NAME=$1 typeset TimeStamp="not defined" typeset toRemove="not defined" umask 002 function TimeStamp { TimeStamp=`(set \`/bin/date +%d-%b-%y@%H:%M:%S\`; /bin/echo $1)` print "TimeStamp: $TimeStamp" return 0; } function cleanup { for Item in `/bin/ls $SYS_NAME*` do toRemove=$Item print "processing: $toRemove" if [[ $toRemove != $SYS_NAMEc && $toRemove != $SYS_NAMEc-$TimeStamp && $toRemove != $SYS_NAMEc.1 && $toRemove != $SYS_NAMEc.1-$TimeStamp && $toRemove != "cleanup.ksh" ]] then rm -Rf $toRemove print "$toRemove removed" else print "I'm not moving: $toRemove" fi done return 0; } function backup { if [[ -s ${SYS_NAME}c ]] then /bin/mv ${SYS_NAME}c ${SYS_NAME}c-${TimeStamp} print "${SYS_NAME}c-${TimeStamp} has been created" else print "Could not create a backup for file ${SYS_NAME}c" exit fi if [[ -d ${SYS_NAME}c.1 ]] then /bin/mv ${SYS_NAME}c.1 ${SYS_NAME}c.1-${TimeStamp} print "${SYS_NAME}c.1-${TimeStamp} directory has been created" else print "Could not create a backup for directory ${SYS_NAME}c.1" exit fi return 0; } TimeStamp backup cleanup |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
You didn't brace the if properly:
if [[ $toRemove != $SYS_NAMEc && $toRemove != $SYS_NAMEc-$TimeStamp && $toRemove != $SYS_NAMEc.1 && $toRemove != $SYS_NAMEc.1-$TimeStamp && $toRemove != "cleanup.ksh" ]] $SYS_NAMEc should be ${SYS_NAME}c ...etc... -mschwage |
|
#3
|
|||
|
|||
|
Thank you, -mschwage.
I have another version of this script where i did what you suggested to do awhile ago and it did not resolve my issue. What you are saying about braces will treat variable's value a little bit differently. My script is able to recognize the directories names properly, but they are not getting removed. The problem is that files are removed by script but directories are not. I would like to understand why. Thanks, |
|
#4
|
|||
|
|||
|
Could be a permissions problem. Remove the -f from the rm -R and see what happens.
If you have a file owned by someone else in your directory, as long as you own the directory, you can remove it with -f. But if you don't use -f, it will complain. My guess is that you don't own one or more files in the directory. Anyway, the -f is hiding your error from you so it's difficult to know at this point... -mschwage |
|
#5
|
|||
|
|||
|
Thank you…
I did what your said even though was in doubt this will fix the problem. I’m owning files and directories. I’m currently developing this script, so everything is done in my home directory. I should not have any permissions related problem for the reason that backup is created by the script, another words by the same owner… |
|
#6
|
|||
|
|||
|
Hmmm... now this is going to taqke serious debugging. You need to run the script with the -x option. Change #!/bin/ksh to #!/bin/ksh -x
Private message me the output. -mschwage |
|
#7
|
|||
|
|||
|
would you please be so kind and send an -email to me, so I could reply to you with output?
I'm thinking now that problem is in this filename_TimeStamp, which cannot be read by OS (or script, or shell) correctly. what "+" means in debugger? Many thank! Appreciate your help! |
|||
| Google The UNIX and Linux Forums |