- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: script
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
Discussions
Discussions
Discussions
Forums
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
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
тАО03-05-2008 07:55 PM
тАО03-05-2008 07:55 PM
I have to write a shell script for the below algorithm. Any assistance..?
Surely appreciated. Thanks
1.execute: a command
2.after execution completes, read job_1000345.log and look for a message "Uptodate"
3.if the message is not found, wait 5 seconds and reexecute step 1.
4.if the message is not found after 10 retrys, stop the loop and append the log file: vs.log with "[date 10:31:27] Error Moving ps on Item 1000345, manual intervention is needed".
5.if message is found, exit script
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-06-2008 04:55 AM
тАО03-06-2008 04:55 AM
SolutionWhat have you written thus far?
I assume you know how to execute a command and redirect output to a file.
Using 'grep' is one way to read a file and look for a string or regular expression.
The 'sleep' command allows waiting.
Looping is easily done with a 'while condition which can be "complex".
A basic shell scripting guide and the 'sh-posix' manpages will guide you nicely.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-06-2008 07:39 AM
тАО03-06-2008 07:39 AM
Re: script
Please advice.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-06-2008 07:58 AM
тАО03-06-2008 07:58 AM
Re: script
> not sure how can i check an out put after greping an item from a log file and depending on that i have to perform one or the other task.
OK, look at the various options of 'grep' in the manpages. For example:
# grep local /etc/hosts
127.0.0.1 localhost loopback
# grep -c local /etc/hosts
1
# grep -q local /etc/hosts && echo "I matched" || echo "I didn't match"
I matched
# grep -q LOCAL /etc/hosts && echo "I matched" || echo "I didn't match"
I didn't match
In the first example, you could capture the output and test for emptiness or not:
RESULT=$(grep local /etc/hosts)
if [ -z "${RESULT}" ]; then
echo "nothing found"
else
echo "found something
fi
In the second example, you would test the count returned:
RESULT=$(grep -c local /etc/hosts)
if [ "${RESULT}" = 0 ]; then
echo "nothing found"
else
echo "found something
fi
In the third example, above, the return value from the 'grep' tells whether or not we had a match.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-06-2008 08:21 AM
тАО03-06-2008 08:21 AM
Re: script
Thanks so much it really helped..i'm almost done...but would like to that once the condition is 0 i will have to reissue the command in 5 seconds ..after 10 retries i have to append an info in a log file and exit.Thanks for the assistance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-06-2008 09:13 AM
тАО03-06-2008 09:13 AM
Re: script
> but would like to that once the condition is 0 i will have to reissue the command in 5 seconds ..after 10 retries i have to append an info in a log file and exit.Thanks for the assistance
OK, here's an example:
#!/usr/bin/sh
typeset -i COUNT=0
typeset -i SEEN=0
while (( ${COUNT} < 10 ))
do
grep -qs "UPDATED" /var/tmp/mylog && { SEEN=1; echo "OK!"; break; }
let COUNT=${COUNT}+1
sleep 5
done
echo "SEEN=${SEEN}...going away"
exit 0
...Look at the manpages for 'sh-posix' and 'grep' for more information. If the 'grep' returns zero (0) meaning one or more matches, "OK" is printed, the variable SEEN is set to one (1) and the loop immediately exited.
Notice the use of the '-s' switch with 'grep' to suppress error messages for for nonexistent or unreadable files.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-06-2008 09:35 AM
тАО03-06-2008 09:35 AM