Need help in creating shell script in hp-ux (310 Views)
Reply
Occasional Advisor
Nagaraj Kris
Posts: 14
Registered: ‎01-10-2008
Message 1 of 7 (310 Views)
Accepted Solution

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.
Outstanding Contributor
Pete Randall
Posts: 16,205
Registered: ‎11-03-1996
Message 2 of 7 (310 Views)

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
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 3 of 7 (310 Views)

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...
Occasional Advisor
Nagaraj Kris
Posts: 14
Registered: ‎01-10-2008
Message 4 of 7 (310 Views)

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
Acclaimed Contributor
Dennis Handly
Posts: 25,184
Registered: ‎03-06-2006
Message 5 of 7 (310 Views)

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

[ Edited ]

>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.

Occasional Visitor
GZWJ63
Posts: 1
Registered: ‎01-12-2014
Message 6 of 7 (257 Views)

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

Acclaimed Contributor
Dennis Handly
Posts: 25,184
Registered: ‎03-06-2006
Message 7 of 7 (247 Views)

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.

 

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.