Operating System - HP-UX
1752762 Members
5015 Online
108789 Solutions
New Discussion юеВ

Need help in creating shell script in hp-ux

 
SOLVED
Go to solution
Nagaraj Kris
Occasional Advisor

Need help in creating shell script in hp-ux

Greetings to everyone, I would be greatful if someone could help me out for creating the shell script which would be applied on 11.23 HP-Ux OS.

Every hour search for specific files name formats in specified directories:

/test/dir1/dir2 search for l50*.txt.*
/test/dir1/dir3 search for l50*.txt.*

/test/dir1/dir2 search for S0**.txt.*
/test/dir1/dir3 search for S0**.txt.*

Exception l503a.txt on the /test/dir1/dir3.

And if the file exists with creation time more than an hour back from the time when scan starts an email alert should be fired to abc@test.com with information on concerned file names.

Please note: No alter should be fired for file I503a.txt in dir /test/dir1/dir3

Thanks in advance for your help and support.

Nag.
6 REPLIES 6
Pete Randall
Outstanding Contributor

Re: Need help in creating shell script in hp-ux

Do a man on find. Pay particular attention to the -newer option. Now do a man on touch so you can figure out how to create a reference file for find's -newer option. Lastly, do a man on cron.


Pete

Pete
James R. Ferguson
Acclaimed Contributor
Solution

Re: Need help in creating shell script in hp-ux

Hi:

I'll provide the guts of your answer, just as I did to a nearly identical question by you earlier this month:

If you are looking for files modifed in the last hour, use Perl:

# perl -MFile::Find -le 'find(sub{print if -f $_ && -M _ < (1/24) && m/(l50|S0).*\.txt/},"/test")'

This finds files in the specified directory that are 1/24 of a day (one hour) or less in age. This age is the *modification* age of the file. There is no such thing as a "creation" timestamp in Unix.

If you would like to use pure shell:

# touch -amt 01101530 /tmp/myref
# find /home/myref -type f -newer /tmp/myref -name "abc*"

Of course, the "problem" in the shell solution is that you have to perform a touch of a reference file to create the one-hour delta everytime you want to search! The Perl solution obviates that.

Regards!

...JRF...
Nagaraj Kris
Occasional Advisor

Re: Need help in creating shell script in hp-ux

Hello Sir,

Thanks a lot for your inputs, I appreciate your speedy reply, i would try this out on the test server, and would update you about the same

thanks

Nag
Dennis Handly
Acclaimed Contributor

Re: Need help in creating shell script in HP-UX

>Every hour search for specific files name formats in specified directories:

If you don't care about the first time for the "hour back" limitation you can do:
DIR=/test/dir1
RF=ref_file
if [ ! -f ${RF}2 ]; then
    touch ${RF}2
fi
mv ${RF}2 ${RF}1
touch ${RF}2 # for next time

find $DIR/dir2 \( -name "l50*.txt.*" -o -name "S0**.txt.*" \) ! -newer ${RF}1 > notify_file
find $DIR/dir3 \( -name "l50*.txt.*" -o -name "S0**.txt.*" \) ! -newer ${RF}1 |
grep -v l503a.txt >> notify_file

if [ -s notify_file ]; then
    mailx -s "found files" abc@test.com < notify_file
fi

>And if the file exists with creation time

You can only find modification times.

GZWJ63
New Member

Re: Need help in creating shell script in hp-ux

Hi i am an SAP basis consultant

i require an script to run in my system to take the files within the test folder and send it to my mail

the same issue as yours but for me age limit is okay

it would be better every hour i get an mail intimation of the files within the specified folder

kidnly help me out with an script that helps to ful fil my needs

Dennis Handly
Acclaimed Contributor

Re: Need help in creating shell script in HP-UX

>to take the files within the test folder and send it to my mail

 

I'm not sure why you can't figure this out from the various posts.  They show how to use find and a reference file.

And how to mail the results.

 

>every hour I get an mail intimation of the files within the specified folder

 

You should set this up in crontab.