The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
recovering files removed with rm jack1981 UNIX for Dummies Questions & Answers 4 09-15-2006 08:06 AM
setfacl -x doesn't shows it removed the ACL braindrain Shell Programming and Scripting 0 08-01-2006 06:09 AM
Will Old Files Be Removed sunsation UNIX for Dummies Questions & Answers 5 06-27-2005 01:24 AM
i have removed my email address K-ONE Post Here to Contact Site Administrators and Moderators 1 04-10-2005 09:45 AM
removed cdroms still appear mounted DarkLord UNIX for Dummies Questions & Answers 1 01-15-2003 02:55 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-15-2005
slavam slavam is offline
Registered User
  
 

Join Date: Aug 2004
Location: California
Posts: 14
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
  #2 (permalink)  
Old 11-16-2005
mschwage mschwage is offline
Registered User
  
 

Join Date: Jul 2005
Location: Oak Park, IL
Posts: 102
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 (permalink)  
Old 11-16-2005
slavam slavam is offline
Registered User
  
 

Join Date: Aug 2004
Location: California
Posts: 14
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 (permalink)  
Old 11-16-2005
mschwage mschwage is offline
Registered User
  
 

Join Date: Jul 2005
Location: Oak Park, IL
Posts: 102
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 (permalink)  
Old 11-16-2005
slavam slavam is offline
Registered User
  
 

Join Date: Aug 2004
Location: California
Posts: 14
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 (permalink)  
Old 11-16-2005
mschwage mschwage is offline
Registered User
  
 

Join Date: Jul 2005
Location: Oak Park, IL
Posts: 102
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 (permalink)  
Old 11-17-2005
slavam slavam is offline
Registered User
  
 

Join Date: Aug 2004
Location: California
Posts: 14
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!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:59 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0