Computing.Net > Forums > Unix > Shell script and cron job

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.

Shell script and cron job

Reply to Message Icon

Name: Collis King
Date: September 14, 2002 at 21:27:59 Pacific
OS: SunOS 5.7
CPU/Ram: Sun Solaris
Comment:

I am new to the UNIX operating system, and have a small task to be accomplished. Every thursday I need to check a certain directory
(/etc/custom/logs/ob) and if any files have been added/modified in the past 10 days an email has be sent to me with the new/modified files.

I understand that a script has be written along with a cron job which will trigger the script at weekly intervals. But thats where my knowledge ends. Please guide me further.

Thanks,

Collis



Sponsored Link
Ads by Google

Response Number 1
Name: immulett
Date: September 15, 2002 at 22:06:13 Pacific
Reply:

OK...of course you know that in cron you'll have to set the verbage to something like this:

0 0 * * * 4 /pathtoshellscript

and of course give it full permissions so that it's executable. Now, for the meat of your question. You'll have to write a script that sounds kinda like this....

$DAYS='cut-c1-2'
$PASTENDAYS='date | cut -c(the numbers of the characters where the day is in the string)' (or something to that effect with some arithmetic subtracting 10 days)

cd /etc/custom/logs/ob
l | cut -c(the number of the characters which contain the "date" section AND the "filename" section then...)>>tmp1
for i in 'cat tmp1'
if $DAYS => $PASTENDAYS
then cat $i >>tmp2
else
next i
for a in 'cat tmp2'
echo $a >>finalfile.txt
cat $a >>finalfile.txt
next a

---then mail finalfile.txt to yourself---

I'm a little rusty but i hope that helps


0

Response Number 2
Name: Jerry Lemieux
Date: September 16, 2002 at 10:03:31 Pacific
Reply:

The script you need should use the find command. Use the man pages for find and look at -mtime option. The script posted above will not work. Cutting out the days will not provide an allowance for a change in months.

find /dirname -mtime -10 -print

Jerry


0

Response Number 3
Name: immulett
Date: September 17, 2002 at 09:45:53 Pacific
Reply:

Yep......
Jerry's right. I emailed you some corrections.
kris......


0

Response Number 4
Name: helen
Date: September 18, 2002 at 13:00:30 Pacific
Reply:

Dear Sir.
I wrote a program switching printer job for the users.sometime work sometime doesn't work almost work for me not for users.someone told me to wrote a script for login(we don't want users know the password)and permission for users use lpalt.... when users got to the unix that ask them password: 12345. so I don't know how to write a script for all them,i used nuix command " lpalt Q12-1235 -dQ13".


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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: Shell script and cron job

Want to run a shell script through cron job www.computing.net/answers/unix/want-to-run-a-shell-script-through-cron-job/8446.html

Unix shell script and Oracle data www.computing.net/answers/unix/unix-shell-script-and-oracle-data/5298.html

Running a shell script from cron www.computing.net/answers/unix/running-a-shell-script-from-cron/4091.html