- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: script error
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
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
06-13-2009 12:24 PM
06-13-2009 12:24 PM
I have a script used for obtain details of logins from syslog.i have assigned data1=Jun and
data2=9.
i can obtain jun 9 login details.But if i change data2=10 ,no output shown.i think this is due to double didgit(10).
please help me on this
regards
himacs
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2009 12:34 PM
06-13-2009 12:34 PM
Re: script error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2009 12:36 PM
06-13-2009 12:36 PM
Re: script error
Thanx for the reply..
#!/bin/sh
#date1=`date|awk '{print $2}'`
#date2=`date|awk '{print $3}'`
date1=Jun
date2=8
hostname=`hostname`
echo "___________________________________________________________________"
echo " $hostname - System Login Details "
echo "___________________________________________________________________"
echo "DATE TIME ID FROM IP "
echo "___________________________________________________________________"
grep -i sshd syslog.log|grep -i keyboard-interactive |grep "$date1 $date2" |awk
'{print $1" "$2" "$3" "$9" "$11}'
the script gives details of logins on that day.
regards
himacs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2009 02:08 PM
06-13-2009 02:08 PM
SolutionYour problem arises when you do:
grep "$date1 $date2"
The dates in 'syslog.log' are in the format of a three-character month name followed by one space followed by a right-justified, space-filled day.
If you run your code with 'date2=1' you will match (errneously) any day in the month that is a 2-digit day where the first digit is one (1)!
One way to fix this is to declare 'date2' thusly:
# typeset -R2 date2=1
The use of 'typeset' is documented in the 'sh-posix' manpages.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2009 07:00 PM
06-13-2009 07:00 PM
Re: script error
This can be fixed by regexp:
grep "$date1 *$date2"
>JRF: three-character month name followed by one space followed by a right-justified, space-filled day.
This is just broken. They should be fixed fields and zero filled.
I know there are some locales that have space filled and other more evil ones that aren't even fixed widths. But syslog should follow American nerd and be easy to parse.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2009 11:41 AM
06-14-2009 11:41 AM
Re: script error
besides the fact, that the multiple 'grep' pipeline could be done completely in awk, I would at least subsitute the last part in adressing Dennis' remark from
>>
... |grep "$date1 $date2" |awk
'{print $1" "$2" "$3" "$9" "$11}'
<<
to (assuming month-> field 1 ($1); day-> field 2 ($2) )
... | awk -v mon=$data1 -v day=$data2 '$1 == mon && $2 == day {print $1" "$2" "$3" "$9" "$11}'
awk will accept any amount of whitespace here when determining fields.
mfG Peter