1834406 Members
2495 Online
110067 Solutions
New Discussion

script doubt

 
SOLVED
Go to solution
himacs
Super Advisor

script doubt

Hi Gurus,

Below scripts provides login details for current date.
#!/bin/sh
date1=`date|awk '{print $2}'`
date2=`date|awk '{print $3}'`


hostname=`hostname`


grep -i sshd /var/adm/syslog/syslog.log|grep -i keyboard-interactive |grep "$date1 *$date2" |awk '{print $1" "$2"
"$3" "$9" "$11}'



Actually i want collect the details for previous date means yesterday's.

Plz help me to edit the script for the same.

regards
himacs
7 REPLIES 7
Tingli
Esteemed Contributor

Re: script doubt

Just search "yesterday" in this forum with numerous answers. Here is one example:

YESTERDAY=$(TZ=$(date +%Z)+24; date '+%b %e')
James R. Ferguson
Acclaimed Contributor
Solution

Re: script doubt

Hi Himacs:

Playing +-24 hours with the TZ variable works only for UTC (GMT) timezones. You are better using a simple Perl snippet where this doesn't matter. That is, it is usable at anytime in your localtime:

# YESTERDAY=$(perl -MPOSIX -le 'print strftime "%b %e",localtime(time-(60*60*24))')

# echo "$YESTERDAY"
Aug 3

You can use any of the formatting directives you think about when you use the 'date' command. The '%e' specification yields the day of the month with space fill whereas the '%d' uses zero-fill.

Regards!

...JRF...
himacs
Super Advisor

Re: script doubt

Hi James,Tinqli

thanx for ur replies.

James, i have used the script given by you.

Its worked fine.I got the desired output.full points assigned

But plz tell me whether we can use perl scripts in hpux?

$(perl -MPOSIX -le 'print strftime "%b %e",localtime(time-(60*60*24))')

as m new into scripting world, i have lot more doubts.
and plz suggest with document with basic scripting..

thanx once again for ur support..


regards
himacs
Mel Burslan
Honored Contributor

Re: script doubt

If you are interested in learning PERL, the authoritative book in my opinion is "Learning Perl" from O'reilly media:

http://oreilly.com/catalog/9781565922846/

If you are asking about shell programming, another O'reilly book comes to mind, "Learning the Korn Shell":

oreilly.com/catalog/9780596001957

But there is no better way than learning it by trying it out on your own, preferably under a project deadline :)

Hope this helps
________________________________
UNIX because I majored in cryptology...
James R. Ferguson
Acclaimed Contributor

Re: script doubt

Hi (again) Himacs:

> But plz tell me whether we can use perl scripts in hpux?

Absolutely! Perl is used by several tools within the HP-UX operating system; most notably by Bastille and SWA.

Perl has been installed with HP-UX for a long, time.

# swlist | grep -i perl

By default, perl lives in '/opt/perl' with a symbolic link from '/usr/bin/perl':

# whereis perl

The script I offered you is designed to be incorporated into a shell script. It gives the 'YESTERDAY' shell variable the month and day for yesterday in your timezone.

> and plz suggest with document with basic scripting.

Yes, you need to become somewhat fluent in shell scripting. In HP-UX the standard shell is the POSIX shell ('/usr/bin/sh' or '/sbin/sh' for root).

Closely related to the POSIX shell is the Korn (ksh) shell and the favorite of the Linux community, the Bash shell. They are similar, but on HP-UX use the POSIX shell. You must for root or you will render your system unstartable.

There are a number of good books on shell programming. A free guide is:

http://docs.hp.com/en/B2355-90046/index.html

...and a very nice resource is:

http://www.shelldorado.com/

Regards (and happy scripting!)

...JRF...




himacs
Super Advisor

Re: script doubt

Hi James , Mel

Thanx for the suggestions..

As m started peeping into scripting world, u can expect more posts from me.:)

Jai ho itrc

regards
himacs
Bill Hassell
Honored Contributor

Re: script doubt

> But plz tell me whether we can use perl scripts in hpux?

Perl is just one the hundreds of commands available in HP-UX. Commands like awk and sed and date are simply tools that can be called from any script (as you have with awk). You can learn Perl is great detail and write complete Perl-only scripts, but just like awk, you can accomplish a lot with simple one-liners.

Here are some 1-liners:

awk
http://www.catonmat.net/blog/awk-one-liners-explained-part-one/

Perl
http://www.ibm.com/developerworks/linux/library/l-p101/



Bill Hassell, sysadmin