GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Shell Script
Operating System - HP-UX
1844295
Members
3132
Online
110230
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
09-26-2007 02:59 AM
09-26-2007 02:59 AM
I am writing a script to get yesterdays users who are logged in.
The script works fine but need to make few changes to the script so that it echo “No users Yesterdays users logged in” if it finds no user from yesterday logged and should display yesterdays users if they are logged in
See example below:
Check if yesterdays users still logged
=============================================================
gmt1 pts/7 Sep 25 09:58 0:37 24165 dev1:1.0
Check if any critical errors in syslog
=============================================================
and I get this O/P when no users logged in and no errors
Check if yesterdays users still logged
=============================================================
Check if any critical errors in syslog
=============================================================
How can I make changes to the script so that if no errors then it should display as below
Check if yesterdays users still logged
=============================================================
No yesterdays users logged
Check if any crucial erros in syslog
=============================================================
No critical errors logged
Part of my script as below:
#This function checks if yesterdays users were killed by OPS
function check_yesterday_users
{
echo >> $LOGFILE
echo "Check if yesterdays users still logged" >> $LOGFILE
echo "===============================" >> $LOGFILE
echo >> $LOGFILE
who -u | grep "$1" >> $LOGFILE
}
The script works fine but need to make few changes to the script so that it echo “No users Yesterdays users logged in” if it finds no user from yesterday logged and should display yesterdays users if they are logged in
See example below:
Check if yesterdays users still logged
=============================================================
gmt1 pts/7 Sep 25 09:58 0:37 24165 dev1:1.0
Check if any critical errors in syslog
=============================================================
and I get this O/P when no users logged in and no errors
Check if yesterdays users still logged
=============================================================
Check if any critical errors in syslog
=============================================================
How can I make changes to the script so that if no errors then it should display as below
Check if yesterdays users still logged
=============================================================
No yesterdays users logged
Check if any crucial erros in syslog
=============================================================
No critical errors logged
Part of my script as below:
#This function checks if yesterdays users were killed by OPS
function check_yesterday_users
{
echo >> $LOGFILE
echo "Check if yesterdays users still logged" >> $LOGFILE
echo "===============================" >> $LOGFILE
echo >> $LOGFILE
who -u | grep "$1" >> $LOGFILE
}
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2007 03:26 AM
09-26-2007 03:26 AM
Solution
echo >> $LOGFILE
echo "Check if yesterdays users still logged" >> $LOGFILE
echo "===============================" >> $LOGFILE
echo >> $LOGFILE
who -u | grep "$1" >> $LOGFILE
add immediately after the line above:
if [ $? = 1 ]
then
echo "No yesterdays users still logged" >> $LOGFILE
fi
the grep will return 1 if no matches found, 0 if they are. similar logic applys to the syslog error piece
echo "Check if yesterdays users still logged" >> $LOGFILE
echo "===============================" >> $LOGFILE
echo >> $LOGFILE
who -u | grep "$1" >> $LOGFILE
add immediately after the line above:
if [ $? = 1 ]
then
echo "No yesterdays users still logged" >> $LOGFILE
fi
the grep will return 1 if no matches found, 0 if they are. similar logic applys to the syslog error piece
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2007 03:29 AM
09-26-2007 03:29 AM
Re: Shell Script
I am not going to bother to answer your specific questions because there is a fundamental flaw in your design. You are relying upon the "who" command to tell you who is on the system. Regardless of the UNIX flavor, who is the system's "best guess" as to who is actually on the system. Using who, your script will work well almost all the time --- which is the worst kind of problem to debug. Sure you can use fwtmp to fix utmp when users are not logged off cleanly but you are really just fixing the symptoms of the problem. Rather than using who, use the process table (ps command) because it is reliable and trustworthy.
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2007 03:39 AM
09-26-2007 03:39 AM
Re: Shell Script
Thanks
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