The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Special Char in Multiple Files thinakarmani Shell Programming and Scripting 5 12-12-2006 11:05 AM
shell script: deleting files from a directory onlyc Shell Programming and Scripting 1 07-09-2006 07:41 AM
cron not deleting file baanprog UNIX for Dummies Questions & Answers 1 05-23-2006 10:08 AM
Problem deleting file with special character hart1165 UNIX for Dummies Questions & Answers 2 12-07-2005 11:29 AM
Can't stop shell interpreting special characters Doug97 Shell Programming and Scripting 2 11-23-2005 09:41 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 07-14-2003
ManfredWL ManfredWL is offline
Registered User
  
 

Join Date: Jul 2003
Location: Munich
Posts: 6
Question CRON-Job / Shell-Skript deleting special files

Just I'm trying to find script, which will do the following job:
1. as a CRON-Job it shoult
a) delete files which will be either older than 24 hours or
b) all files within
a) a directory deleting recursive
b) only a special directory.
2. write an error-/Delete_log or not.

lets say, the shell-skript will be names as df.sh
so it would be executed with three parameters:

df.sh j j n

this will be submitted as Parameters and - as far as I know?? - could be read with:

case $1 in
[jJ]) VAR1=1; export VAR1;;
[nN]) VAR1=0; export VAR1;;
*) echo "ERROR1"; PERROR=1; export PERROR;;
esac
case $2 in
[jJ]) VAR2=1; export VAR2;;
[nN]) VAR2=0; export VAR2;;
*) echo "ERROR2"; PERROR1=1; export PERROR;;
esac
case $3 in
[jJ]) VAR3=1; export VAR3;;
[nN]) VAR3=0; export VAR3;;
*) echo "ERROR3"; PERROR2=1; export PERROR;;
esac

why didn't it work??

When using
df.sh j jn j
the errormessage for Var2 will be shown

when using
df.sh jj jj jj
all errormessages will be shown

When useing
df.sh j j j
no errormessages, but the Variables are not set! WHY??

Any help would be nice.

thanks
Manfred
  #2 (permalink)  
Old 07-14-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
In your case statements, [jJ] is searching either for a "j" or a "J" .. the same with [nN].
Quote:
When using
df.sh j jn j
the errormessage for Var2 will be shown
$1="j" , $2="jn" , $3="j"
"jn" doesn't equal "j" , "J" , "n" or "N", so you get the error.

You'd need to actually test for "jn"...
Code:
case $2 in
[jJ]) do something;;  # if $2="j" or $2="J"
[nN]) do something;;  # if $2="n" or $2="N"
jn) do something;;    # if $2="jn"
jj) do something;;    # if $2="jj"
*) echo "ERROR2"; PERROR1=1; export PERROR;;
esac
  #3 (permalink)  
Old 07-15-2003
ManfredWL ManfredWL is offline
Registered User
  
 

Join Date: Jul 2003
Location: Munich
Posts: 6
Exclamation whats wrong with doing something?

Thanks,

that's what I say.
Doing it with wrong parameters like
df.sh j jj n
this will show, that $2 is a wront parameter, because only j or J would be accepted .

But the thing
.... doing something didn't work.

lets say, I'll getting the first j - which would say set VAR1 to 1.
This woun't work with this part. Why??

Thanks
Manfred
  #4 (permalink)  
Old 07-15-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
What makes you think it's not working? Are you getting a specific error message? Are you just not seeing anything on the screen? The export command isn't going to show you anything... if you want some visual confirmation that VAR1 is set, then use a line of code like "[jJ]) VAR1=1; export VAR1; echo $VAR1;;"
  #5 (permalink)  
Old 07-15-2003
ManfredWL ManfredWL is offline
Registered User
  
 

Join Date: Jul 2003
Location: Munich
Posts: 6
Hi,
that's right.
What makes me worring:
Theres - of course - nothing on screen, but the VAR1..VAR3 are not set. Just looking with SET-Command you won't find them. Therefor I thought, something wrong the Syntax, the script is running on ksh might be here something wrong??

That's my problem.

thanks
Manfred
  #6 (permalink)  
Old 07-15-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
Try placing the SET command in your script somewhere so you can see what variables are set during execution... the variables should be set while the script is running. They are unset when the script ends.
  #7 (permalink)  
Old 07-16-2003
ManfredWL ManfredWL is offline
Registered User
  
 

Join Date: Jul 2003
Location: Munich
Posts: 6
Thumbs up thanks

very ugly, but it works!
Having to echo first the parameters, than within statement controlling with echo too and it works. But - please - don't aks why??

But even it works now.
Just btw -
to delete files from an directory comming with
... find <path> -ctime 0 -exec rm -i {}\;

works fine up to that point, when not deleting recursive beginning on specified path.

But what to do, when only deleting the files within this directory and not with subdirs??
This would .- perhaps - work, but after path you need to specify - as fas as I know - something else for the grep, otherwise it would be the same as without grep.
Any possibility - perhaps comming on to "\" counting??

.... find <path> -ctime 0 | greb <path> ??? -excec .....;

Thanks in advance for your help up to now.

Manfred
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 01:45 AM.


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