- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Hi, need assistance with script again ...Please re...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2011 09:34 AM
05-29-2011 09:34 AM
we want to create a script on Hp Unix server in which
Description:
There is a Filesystem with name:
/home/maestro
It should remove some subdirectories in it which I will explain below, when Filesystem size....reaches 80%
the directories under this filesystem are :
/home/maestro/stdlist/2011.05.29
/home/maestro/stdlist/logs
/home/maestro/stdlist/traces
It should delete all the directories starting from 2011* except last two days
and It should delete all the files under Logs and Traces except last two days...
Please suggest something on the same :(
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2011 10:24 AM
05-29-2011 10:24 AM
SolutionSomething like this should work:
find /home/maestro/stdlist -type d -name "2011*" -mtime +2 -exec rm -rf {} +
find /home/maestro/stdlist/logs /home/maestro/stdlist/traces -type f -mtime +2 -exec rm -f {} +
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2011 10:30 AM
05-29-2011 10:30 AM
Re: Hi, need assistance with script again ...Please reply...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2011 11:40 AM
05-29-2011 11:40 AM
Re: Hi, need assistance with script again ...Please reply...
for example:
#!/bin/sh
a=`bdf | grep /home/maestro | awk '{print $5}'|cut -d % -f1`
if [ $a -gt 80 ]
then find /home/maestro/stdlist -type d -name "2011*" -mtime +2 -exec rm -rf {} +
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2011 12:05 PM
05-29-2011 12:05 PM
Re: Hi, need assistance with script again ...Please reply...
#!/bin/sh
a=`bdf | grep /home/maestro | awk '{print $5}'|cut -d % -f1`
if [ $a -gt 80 ]
then find /home/maestro/stdlist -type d -name "2011*" -mtime +2 -exec rm -rf {} + && find /home/maestro/stdlist/logs /home/maestro/stdlist/traces -type f -mtime +2 -exec rm -f {} +
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2011 12:14 PM
05-29-2011 12:14 PM
Re: Hi, need assistance with script again ...Please reply...
You guys made my day :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2011 01:38 AM
05-30-2011 01:38 AM
Re: Hi, need assistance with script again ...Please reply...
cheers :D
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2011 05:48 AM
05-30-2011 05:48 AM
Re: Hi, need assistance with script again ...Please reply...
Instead of creating a second and third process to finish the work the first process could easily complete, as in:
# a=`bdf | grep /home/maestro | awk '{print $5}'|cut -d % -f1`
...you could do:
# a=$(bdf | awk '/\/home\/maestro/ {split($5,ary,"%");print ary[1]})
This eliminates the 'grep' and the 'cut' processes and lets 'awk' match and parse everything you want.
Note the $( ... ) syntax instead of the archaic back-ticks too.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2011 09:09 AM
05-30-2011 09:09 AM
Re: Hi, need assistance with script again ...Please reply...
All in one line....
I will try this as well....
Thanks a ton !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2011 12:48 PM - last edited on 07-07-2011 08:14 AM by Kevin_Paul
05-30-2011 12:48 PM - last edited on 07-07-2011 08:14 AM by Kevin_Paul
Re: Hi, need assistance with script again ...Please reply...
Hi (again):
> Thanks a ton !
If you re happy with the answers you received, please see the following about assigning points:
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2011 01:00 PM
05-30-2011 01:00 PM
Re: Hi, need assistance with script again ...Please reply...
I gave 10 to everyone :) :) :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2011 02:11 PM - last edited on 08-02-2011 07:24 AM by Kevin_Paul
05-30-2011 02:11 PM - last edited on 08-02-2011 07:24 AM by Kevin_Paul
Re: Hi, need assistance with script again ...Please reply...
One thing you need to be careful about the bdf output is that sometimes the lines are split into two if the mount point is long.
http://h30499.www3.hp.com/t5/Languages-and-Scripting/script-to-alert-when-File-system-has-reached-gt-87/m-p/5265424#M41339
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2011 03:28 PM
05-30-2011 03:28 PM
Re: Hi, need assistance with script again ...Please reply...
I am facing one more challenge in this script..I wanted to keep it simple which Ican understand so I have made a big however easy script..
#!/bin/sh
a=`bdf | grep /home/maestro | awk '{print $5}'|cut -d % -f1`
if [ $a -gt 80 ]
then
cd /home/maestro/stdlist
rm -r 2011*
cd /home/maestro/stdlist/logs
rm "2011*
cd /home/maestro/stdlist/traces
rm 2011*
cd /home/maestro/methods/traces
rm *.log
cd /home/maestro | grep "core"
b=$?
if [$b -e 0 ]
then
rm core
else
exit
fi
fi
Now we will be running this script via Maestro..m not sure if anyone aware of this scheduling tool or not? We will not be running it via cron job or something..
Now rght now we are doingthis server manually on the server.. what we do is we login to the server we our ID's .. and then to delete these files we use sudo command for example
sudo rm -r 2011*
Then it ask for a password and then it will remove those files....
Is it possible for the above script to run the commands automatically as sudo?
Please suggest....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2011 07:38 PM
05-30-2011 07:38 PM
Re: Hi, need assistance with script again ...Please reply...
You may want to combine the rms:
rm -rf 2011* logs/2011* traces/2011* ../methods/traces/*.log
(Didn't you want to do that find(1) and keep the last two days?)
>cd /home/maestro | grep "core"
Don't you mean:
cd /home/maestro; ls | grep -q core
>if [ $b -e 0 ]; then
There is no reason for this complexity. Just do:
rm -f core
>Is it possible for the above script to run the commands automatically as sudo?
Yes. You can set up sudo to not have a password and only allow specific users to run a specific script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2011 11:00 PM
06-02-2011 11:00 PM