Computing.Net > Forums > Unix > Write a Bourne Shell Script--help!

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Write a Bourne Shell Script--help!

Reply to Message Icon

Name: Kevine
Date: March 29, 2001 at 22:00:24 Pacific
Comment:

I want to write bourne shell script called clean.Clean should move all files in a specified directory that has not been modified after the specified date, to a directory called .junk. the command should create .junk, if it does not exist.
I don't know how to write it. Somebody can help me...Thanks in advance



Sponsored Link
Ads by Google

Response Number 1
Name: Don
Date: March 30, 2001 at 15:23:34 Pacific
Reply:

Basically like this:

#!/usr/sh

DIR=$HOME/dir1
JUNKDIR=$HOME/.junk

mkdir -p $JUNKDIR
find $DIR -mtime +7 -exec mv {} $JUNKDIR \;

This will move all the files which hasn't been modified in 7 days from "dir1" to ".junk" at your home directory.
I don't test it. but I believe it works.


0

Response Number 2
Name: Chris Beddo
Date: March 30, 2001 at 17:45:22 Pacific
Reply:

You can also create an entry in the crontab like so;

* * * * * $HOME/clean

the "*" 's represent a date and time and are in order listed; minute (0-59),hour (0-23), day of the month (1-31), month of the year (1-12),day of the week (0-6 with 0=Sunday). and the last feild is the LITERAL path to the file you want to execute.

pls do a man on crontab to see more info on this.

and have clean read like this;
#!/usr/sh
cd
ls -al | grep -v "Mar 30 16:28" > tmp1
mkdir $HOME/.junk
for a in tmp1
do
mv $a $HOME/.junk/$a
done
exit 0

NOTE: I used an arbitrary date in my grep line, you should substitute in the date your looking for, however use the same format as what is listed in my grep line and remember its in military time.

NOTE2: This will run at your specified date
ie.(* * * * *) and will grep for files in your home directory which have NOT been modified by your specific date, and move them to a .junk directory branched off of your $HOME

This is a little longer than the other script shown here , but I believe it works, and it gives you some additional stuff to play with :)
good luck
Chris


0

Response Number 3
Name: Kevine
Date: March 30, 2001 at 20:51:09 Pacific
Reply:

Thanks Guy, that did it!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


freeBSD instalation probl... Making own start|stop scr...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Write a Bourne Shell Script--help!

I need help writing a bourne shell scrip www.computing.net/answers/unix/i-need-help-writing-a-bourne-shell-scrip/2184.html

C-shell script help www.computing.net/answers/unix/cshell-script-help/6828.html

Bourne Shell script www.computing.net/answers/unix/bourne-shell-script-/2883.html