CRON-Job / Shell-Skript deleting special files

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting CRON-Job / Shell-Skript deleting special files
# 1  
Old 07-14-2003
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
so it would be executed with three parameters: 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;;
case $2 in
[jJ]) VAR2=1; export VAR2;;
[nN]) VAR2=0; export VAR2;;
*) echo "ERROR2"; PERROR1=1; export PERROR;;
case $3 in
[jJ]) VAR3=1; export VAR3;;
[nN]) VAR3=0; export VAR3;;
*) echo "ERROR3"; PERROR2=1; export PERROR;;

why didn't it work??

When using j jn j
the errormessage for Var2 will be shown

when using jj jj jj
all errormessages will be shown

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

Any help would be nice.

# 2  
Old 07-14-2003
In your case statements, [jJ] is searching either for a "j" or a "J" .. the same with [nN].
When using 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"...
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;;

# 3  
Old 07-15-2003
Error whats wrong with doing something?


that's what I say.
Doing it with wrong parameters like 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??

# 4  
Old 07-15-2003
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  
Old 07-15-2003
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.

# 6  
Old 07-15-2003
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  
Old 07-16-2003
MySQL 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.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cron job that checks for new/recent files

I'm new to shell scripting, and I want to set up a cron job that scans the date/time stamp of all files in a directory, and then if any file is, say, less than 10 minutes old, I want it to execute a command on that file. What would be the best way to go about this? Thanks. Not sure if it makes a... (1 Reply)
Discussion started by: DavidHoffman
1 Replies

2. Shell Programming and Scripting

Cron job and shell script to kill a process if memory gets to high

Hello, I'd like to set a cron job that runs a shell script every 30 minutes or so to restart a java based service if the memory gets above 80%. Any advice on how to do this? Thanks in advance! - Ryan (19 Replies)
Discussion started by: prometheon123
19 Replies

3. UNIX for Dummies Questions & Answers

cron job for the created shell script

Hi am newbie for unix shell.. how to create a cron job for my already created shell script.:confused: Thanks! (1 Reply)
Discussion started by: vidhyaS
1 Replies

4. Solaris

Shell Script gives error when run through cron job.

Hi, The following shell script runs without any problem when executed manulally. USED=$(df -h /arch | tail -1 | awk '{print $5}' | cut -d '%' -f 1) if then find /arch/AUBUAT/ -type f -mtime +0 | xargs rm find /arch/AUBMIG/ -type f -mtime +0 | xargs rm fi But the same gives below... (6 Replies)
Discussion started by: ksadiq79
6 Replies

5. Shell Programming and Scripting

Cron job shell script..

Hey Guys, i was trying out a shell script which has to remove a file for every 90 mins. this is the code i came up with . $ crontab -e file1 file1 contains 30 1 * * * * rm -r /folder1/folder2/somefile.txt Now i need the cron to run for every 90 mins. the problem with this is... (8 Replies)
Discussion started by: Irishboy24
8 Replies

6. Shell Programming and Scripting

cron job - shell code correction

Hi I have a website that is having problem with cron jobs... I have a cron job set up to go to a page with this code... <? include('config.php'); if($_sys->bible_email_frequency == 'DAILY') { $u = new user(); $u->send_bible_email(); } ?> If i send my browser to this page... (2 Replies)
Discussion started by: whybelieve
2 Replies

7. UNIX for Dummies Questions & Answers

Cron job to delete files

Hi everyone! I'm sorry, I'm a total noob but would really appreciate any advice or help. I want to create a cron job that would run every hour and would look inside a few different folders. If any new files were created within those folders within the last hour they would be destroyed, but any... (2 Replies)
Discussion started by: jessn
2 Replies

8. UNIX for Dummies Questions & Answers

Cron Job Config files

Hi All, I have created 2 shell scripts and set Cron jobs which runs it at various frequencies.The first one which runs every 2 minutes Monday to Friday and another cron job runs at 11PM on the last Sunday of every month. I have given the cron job entries below. Was wondering whether instead... (5 Replies)
Discussion started by: valluvan
5 Replies

9. UNIX for Dummies Questions & Answers

shell script run by user or cron job ?

My shell script runs fine both as a cron job and when i issue it. However, I wish to differentiate when it runs as a cron-job so the "echo" statements are not issued (they get mailed to me, which i don't want). I tried checking $USER but since the cron was created in my user that does not... (5 Replies)
Discussion started by: sentinel
5 Replies

10. Shell Programming and Scripting

Backup with shell program and cron job.

Hi, The object of my program is to take automatic backup on daily basis to different folders. I have created the respective folders. when I execute below given shell program manually it is working perfectly and taking the backup to respective folder. #!/bin/sh #script to take backup on... (1 Reply)
Discussion started by: jarkvarma
1 Replies
Login or Register to Ask a Question

Featured Tech Videos