HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Script Help
Operating System - Linux
1828586
Members
2623
Online
109982
Solutions
Forums
Categories
Company
Local Language
back
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
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
06-24-2004 02:36 PM
06-24-2004 02:36 PM
Hi gurus,
I can't see any problem in my below perl script. There are 4 rsyn deamons. My script to check if 4
daemons are running.
#!/bin/perl
my $CMD;
$CMD=system("ps -ef |grep -v grep |grep rsync |wc -l");
if ($CMD != 4)
{
print "There should 4 rsync daemons running, only x process running\n";
}
But the script prints message even there are 4 daemons running. I know it's a basic and simple script but I am missing something.
Can someone point me the problem?. System is RH9.
Thanks
Siva
I can't see any problem in my below perl script. There are 4 rsyn deamons. My script to check if 4
daemons are running.
#!/bin/perl
my $CMD;
$CMD=system("ps -ef |grep -v grep |grep rsync |wc -l");
if ($CMD != 4)
{
print "There should 4 rsync daemons running, only x process running\n";
}
But the script prints message even there are 4 daemons running. I know it's a basic and simple script but I am missing something.
Can someone point me the problem?. System is RH9.
Thanks
Siva
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2004 02:43 PM
06-24-2004 02:43 PM
Solution
What you're doing here is getting the handle on a system process, not on the output of a given command. To do that, you need to open the command in a pipe, similar to:
open( FH, "ps -ef | grep -v grep | grep rsync | wc -l |" );
$output =;
if ($output !=) {
print "blah\n";
}
-- (Be aware, that 'wc -l' outputs spaces/tabs infront of your number, so you'd need to clean it up a fair bit first, or possibly just use 'ps -ef | grep -v grep | grep -c rsync' instead).
Although if you're going to be doing something like this, why use a perl script?
As a simple shell script, something like:
#!/bin/bash
if [ "$(ps -ef | grep -v grep | grep -c rsync)" -ne 4 ]
then
echo "There should be 4"
fi
Just some thoughts.
open( FH, "ps -ef | grep -v grep | grep rsync | wc -l |" );
$output =
if ($output !=
print "blah\n";
}
-- (Be aware, that 'wc -l' outputs spaces/tabs infront of your number, so you'd need to clean it up a fair bit first, or possibly just use 'ps -ef | grep -v grep | grep -c rsync' instead).
Although if you're going to be doing something like this, why use a perl script?
As a simple shell script, something like:
#!/bin/bash
if [ "$(ps -ef | grep -v grep | grep -c rsync)" -ne 4 ]
then
echo "There should be 4"
fi
Just some thoughts.
One long-haired git at your service...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2004 04:15 PM
06-24-2004 04:15 PM
Re: Script Help
Stuart,
Thanks for the quick one and the explanation. I need to use perl because of the email function.
Thanks again
Siva
Thanks for the quick one and the explanation. I need to use perl because of the email function.
Thanks again
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2004 04:57 PM
06-24-2004 04:57 PM
Re: Script Help
Fair enough.
With a little playing though, you can get email out of shell scripts just as easily (pipe the body of a message into the 'mail' command *shrug*).
If you're happy using perl though, stick with it! It's truely a fabulous language!
With a little playing though, you can get email out of shell scripts just as easily (pipe the body of a message into the 'mail' command *shrug*).
If you're happy using perl though, stick with it! It's truely a fabulous language!
One long-haired git at your service...
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP