Problem


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Problem
# 8  
Old 07-16-2008
#!/usr/bin/ksh

A=`date +%m`


set +A YEAR 0 0 Jan Feb Mar Apr May Jun Jul Ago Sep Oct Nov Dec

if (( ${A} == 1 )); then
B=Dec
else
B=${YEAR[${A}]}
fi
last -a |grep ${B}
#echo ${B}

I did this, but the client, has the last from last year (Jun of 2007 for example), and i only need the last of jun of this year.
this script prints the month of all years include the current year.

Sorry my english ..thank you for your time
this is what the script print
root pts/1 Mon Jun 30 18:01 - 18:21 (00:19) 172.16.1.7
root console Mon Jun 30 17:54 - 18:14 (00:20)
root pts/1 Mon Jun 30 17:48 - 18:01 (00:12) 172.16.1.7
root pts/1 Fri Jun 27 10:56 - 11:05 (00:08) 172.16.1.6
root pts/2 Thu Jun 26 14:30 - 18:30 (03:59) 172.16.1.6
root pts/1 Thu Jun 26 14:25 - 14:32 (00:07) 172.16.1.5
root pts/1 Wed Jun 25 17:28 - 18:28 (01:00) 172.16.1.5
root pts/2 Tue Jun 24 17:52 - 20:17 (02:25) 172.16.1.4
root pts/1 Tue Jun 24 17:45 - 18:05 (00:19) 172.16.1.3
root pts/1 Tue Jun 24 10:35 - 12:36 (02:01) 172.16.1.3
root pts/2 Mon Jun 23 10:27 - 11:36 (01:09) 172.16.1.3
root pts/1 Mon Jun 23 10:25 - 10:59 (00:33) 172.16.1.1
root pts/1 Fri Jun 20 17:30 - 19:33 (02:03) 172.16.1.1
root pts/1 Fri Jun 20 13:45 - 13:58 (00:13) 172.16.1.1
root pts/2 Fri Jun 20 13:16 - 13:35 (00:19) 172.16.1.10
root pts/1 Fri Jun 20 10:36 - 13:35 (02:59) 172.16.1.10
root pts/1 Thu Jun 19 11:54 - 11:54 (00:00) 172.16.1.10
root pts/1 Thu Jun 19 10:34 - 11:53 (01:19) 172.16.1.10
root pts/2 Wed Jun 18 12:21 - 14:21 (02:00) 172.16.1.10
root pts/2 Wed Jun 18 12:20 - 12:21 (00:01) 172.16.1.10
root pts/1 Wed Jun 18 12:19 - 14:21 (02:02) 172.16.1.10
root pts/1 Tue Jun 17 16:03 - 18:03 (02:00) 172.16.1.10
root ftp Tue Jun 17 12:56 - 12:57 (00:01) 172.16.1.9
root ftp Tue Jun 17 12:56 - 12:56 (00:00) 172.16.1.9
root pts/1 Tue Jun 17 12:49 - 12:57 (00:07) 172.16.1.9
root ftp Tue Jun 17 12:49 - 12:56 (00:06) 172.16.1.9
root pts/1 Fri Jun 13 14:47 - 17:24 (02:36) 172.16.1.9
root pts/1 Fri Jun 13 10:47 - 13:01 (02:14) 172.16.1.9
root ftp Thu Jun 12 16:39 - 16:40 (00:01) 172.16.1.9
root ftp Thu Jun 12 16:39 - 16:39 (00:00) 172.16.1.9
root ftp Thu Jun 12 16:39 - 16:39 (00:00) 172.16.1.9
root ftp Thu Jun 12 16:39 - 16:39 (00:00) 172.16.1.9
root pts/1 Thu Jun 12 16:09 - 16:51 (00:42) 172.16.1.9
root pts/1 Mon Jun 2 12:36 - 12:43 (00:07) 172.16.1.9
I ONLY NEED UNTIL HERE
ope pts/1 Mon Jun 25 00:01 - 00:01 (00:00) 130.120.110.122
ope pts/1 Sun Jun 24 21:57 - 21:57 (00:00) 130.120.110.122
ope pts/1 Mon Jun 18 03:34 - 03:34 (00:00) 130.120.110.122
ope pts/1 Mon Jun 11 00:14 - 00:15 (00:01) 130.120.110.122
ope pts/1 Mon Jun 4 00:01 - 00:01 (00:00) 130.120.110.151
ope pts/1 Mon Jun 26 00:16 - 00:16 (00:00) 130.120.110.82
root pts/1 Sat Jun 24 13:32 - 13:33 (00:00) 172.16.1.3
root console Sat Jun 24 02:24 - 02:24 (00:00)
root pts/3 Sat Jun 24 01:54 - 02:11 (00:17) 130.120.110.112
root pts/2 Sat Jun 24 01:13 - 02:11 (00:58) 130.120.110.112
root pts/1 Sat Jun 24 01:11 - 02:11 (00:59) 130.120.110.112
reboot system boot Sat Jun 24 01:02
root pts/1 Sat Jun 24 00:49 - 00:59 (00:10) 130.120.110.112
reboot system boot Sat Jun 24 00:48
root pts/1 Sat Jun 24 00:40 - 00:45 (00:05) 130.120.110.112
reboot system boot Sat Jun 24 00:36
root console Fri Jun 23 22:07 - 00:29 (02:21) :0
reboot system boot Fri Jun 23 22:02
root pts/4 Fri Jun 23 16:28 - 16:53 (00:24) 130.120.110.112
root pts/4 Fri Jun 23 16:28 - 16:28 (00:00) 130.120.110.112
root pts/4 Fri Jun 23 16:26 - 16:27 (00:01) interb02
root pts/3 Fri Jun 23 16:06 - 16:30 (00:23) 130.120.110.112
root pts/3 Fri Jun 23 10:28 - 12:14 (01:46) 130.120.110.231
root ftp Fri Jun 23 09:32 - 09:47 (00:14) 172.16.1.3
root pts/4 Fri Jun 23 08:54 - 08:54 (00:00) 172.16.1.3
root pts/3 Fri Jun 23 08:35 - 09:47 (01:11) 172.16.1.3
root pts/3 Fri Jun 23 08:34 - 08:34 (00:00) 172.16.1.3
ope pts/3 Sun Jun 18 23:37 - 23:37 (00:00) 130.120.110.223
ope pts/3 Mon Jun 12 00:51 - 00:52 (00:01) 130.120.110.82
ope pts/3 Sun Jun 11 23:31 - 23:31 (00:00) 130.120.110.223
ope pts/3 Mon Jun 5 00:33 - 00:34 (00:01) 130.120.110.223
ope pts/3 Sun Jun 4 23:46 - 23:48 (00:01) 130.120.110.82
root pts/7 Tue Jun 28 12:25 - 12:26 (00:01) interb03
root pts/7 Thu Jun 23 22:25 - 22:47 (00:22) 130.120.110.162
root console Thu Jun 23 22:17 - down (32+17:10) :0
reboot system boot Thu Jun 23 22:13
root pts/7 Thu Jun 23 20:45 - 21:06 (00:20) 130.120.110.162
root console Thu Jun 23 20:25 - 21:05 (00:40) :0
reboot system boot Thu Jun 23 20:23
reboot system boot Thu Jun 23 17:57
root console Thu Jun 23 17:52 - 17:53 (00:00) :0
root pts/3 Thu Jun 23 17:41 - 17:54 (00:12) interb03
root pts/3 Thu Jun 23 17:38 - 17:41 (00:02) interb03
root pts/2 Thu Jun 23 17:28 - 17:54 (00:26) interb03
root pts/2 Thu Jun 23 17:28 - 17:28 (00:00) interb03
root pts/2 Thu Jun 23 17:24 - 17:25 (00:01) interb02
root pts/3 Thu Jun 23 17:16 - 17:25 (00:08) interb02
root pts/2 Thu Jun 23 17:15 - 17:23 (00:08) interb02
reboot system boot Thu Jun 9 19:55
ope pts/2 Thu Jun 9 19:08 - 19:09 (00:01) 130.120.110.89
root ftp Mon Jun 6 13:18 - 13:19 (00:01) 130.120.110.49
root pts/2 Mon Jun 6 13:10 - 13:25 (00:14) interb03
root pts/2 Mon Jun 6 11:19 - 12:54 (01:34) interb03
root pts/3 Wed Jun 30 18:36 - 18:43 (00:06) 130.120.110.231
root pts/2 Wed Jun 30 17:21 - 18:50 (01:29) interb02
root pts/2 Tue Jun 8 12:00 - 12:01 (00:00) interb02
root pts/2 Tue Jun 8 11:53 - 11:53 (00:00) interb02
# 9  
Old 07-16-2008
Try this:

Code:
#!/usr/bin/ksh

A=$(date +%m)

set -A YEAR 0 0 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec

if (( ${A} == 1 )); then
   B=Dec
else
   B=${YEAR[${A}]}
fi
echo ${B}

last -a|nawk -v var="$B" '$0 ~ var{p=1} $0 !~ var && p{exit}p'

Regards
# 10  
Old 07-16-2008
Oh franklin52 yeahhh that works perfectly, one question the command fi is to use to end of file? thank you very very much for your help to all of you..
# 11  
Old 07-16-2008
p{exit}p i had troubles to understand this.sorry
thank you
# 12  
Old 07-16-2008
fi ends the if-else block.

Code:
nawk -v var="$B" '$0 ~ var{p=1} $0 !~ var && p{exit}p'

Code:
$0 ~ var{p=1}

If we find the first var we set the variable p to 1

Code:
$0 !~ var && p{exit}

If the next line don't match the month and p was set: exit.

Code:
p

if p is true (1 in this case) print the line, thus we print the line if we find the first match untill the line that don't match.

Regards
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sed Or Grep Problem OR Terminal Problem?

I don't know if you guys get this problem sometimes at Terminal but I had been having this problem since yesterday :( Maybe I overdid the Terminal. Even the codes that used to work doesn't work anymore. Here is what 's happening: * I wanted to remove lines containing digits so I used this... (25 Replies)
Discussion started by: Nexeu
25 Replies

2. IP Networking

Problem with forwarding emails (SPF problem)

Hi, This is rather a question from a "user" than from a sys admin, but I think this forum is apropriate for the question. I have an adress with automatic email forwarding and for some senders (two hietherto), emails are bouncing. This has really created a lot of problems those two time so I... (0 Replies)
Discussion started by: carwe
0 Replies

3. AIX

AIX OS problem? network problem?

Dear ALL. I installed AIX OS on customer sites. but Only one site is too slow when I connected telnet, ftp.. Ping is too fast. but telnet and FTP is not connected.. of course i check the configuration file on aix but it's normal. Do any Idea?? thanks in advance. - Jun - (3 Replies)
Discussion started by: Jeon Jun Seok
3 Replies

4. UNIX for Dummies Questions & Answers

DHCP problem and eth1 problem

At work I am trying to get this one Linux machine (let's call it ctesgm07) to behave like another Linux machine that we have (let's call it test007). test007 returns the following version info: cat /etc/debian_version: lenny/sid uname -a: Linux test007 2.6.27-7-generic #1 SMP Tue Nov 4... (0 Replies)
Discussion started by: sllinux
0 Replies

5. Red Hat

Mail Problem. Maybe, it is a DNS Problem!

Hi, i've a redhat linux 9 upadated by redhat from 7 version to 9 version. A couple of days ago i was a problem with my mail, in other words i'm not able to get any email nor to send any email. I've a proxy configuration and i tried to set iptables in order to verify the port. The 110,255 and 995... (1 Reply)
Discussion started by: pintalgi
1 Replies

6. AIX

user login problem & Files listing problem.

1) when user login to the server the session got colosed. How will resolve? 2) While firing the command ls -l we are not able to see the any files in the director. but over all view the file system using the command df -g it is showing 91% used. what will be the problem? Thanks in advance. (1 Reply)
Discussion started by: pernasivam
1 Replies

7. Solaris

problem in finding a hardware problem

Hi I am right now facing a strange hardware problem. System get booted with the following error: Fatal Error Reset CPU 0000.0000.0000.0003 AFSR 0100.0000.0000.0000 SCE AFAR 0000.07c6.0000.1000 SC Alert: Host System has Reset It happen 4 or 5 times and get the same error every time.I... (8 Replies)
Discussion started by: girish.batra
8 Replies

8. Shell Programming and Scripting

ssh script problem problem

Hi Please help me with the following problem with my script. The following block of code is not repeating in the while loop and exiting after searching for first message. input_file ========== host001-01 host001-02 2008-07-23 13:02:04,651 ConnectionFactory - Setting session state... (2 Replies)
Discussion started by: pcjandyala
2 Replies

9. Shell Programming and Scripting

problem with dd command or maybe AFS problem

Hi, folks. Sorry for bothering, but maybe someone could help me please. The problem is the following: there is some script that copies files from local file system to AFS. The copying is performed with dd command. The script copies data into some AFS volumes. The problem appeared with one... (0 Replies)
Discussion started by: Anta
0 Replies

10. UNIX for Advanced & Expert Users

SSH Problem auth problem

Hi, Just recently we seem to be getting the following error message relating to SSH when we run the UNIX script in background mode: warning: You have no controlling tty. Cannot read confirmation.^M warning: Authentication failed.^M Disconnected; key exchange or algorithm negotiation... (1 Reply)
Discussion started by: budrito
1 Replies
Login or Register to Ask a Question