 |
05-17-2007, 07:53 AM
|
#1
|
|
Registered Member
Join Date: May 2007
Posts: 5
OS: Vista
|
Bash programming question
Hello!I am a real noob in bash programming and i would like some help (also i dont know very good english so forgive my mistakes)...
I want to write a bash script that finds which of my friends are currently logged in the system and the time of their login or if someone of my friends is not currently logged in when was the time/date of his last login
For example an output of my script could be like this
cat ~/.friends
root John
bash checkfriends.sh
root is ONLINE: Logged in on Wed Apr 25 05:36
John last seen on Wed Apr 25 01:01
Any help would be very appreciated!
__________________
|
|
|
05-17-2007, 10:19 AM
|
#2
|
|
Registered Member
Join Date: May 2007
Posts: 62
OS: Windows XP,Linux
|
Re: Bash programming question
cat /var/log/auth.log |grep login
Of course that won't work if you don't have an auth.log there, or if it's in a very different structure than mine, what OS are you running?
If it does work for you that should be a start however.
__________________
|
|
|
05-17-2007, 10:54 AM
|
#3
|
|
Registered Member
Join Date: May 2007
Posts: 62
OS: Windows XP,Linux
|
Re: Bash programming question
also in place of "grep login" you may use "grep ssh" for remote connections.
I'd recommend looking over auth.conf so you have a better idea.
__________________
|
|
|
05-17-2007, 12:29 PM
|
#4
|
|
Registered Member
Join Date: May 2007
Posts: 5
OS: Vista
|
Re: Bash programming question
I am experimenting with Minix 3!For this i write the scripts!
That command you gave me doesnt work for Minix 3!Unfortunately
I am trying the commands last,or who and awk programming but i havent found a solution!Minix isnt very helpful!
Thanks for the replies
__________________
|
|
|
05-17-2007, 12:48 PM
|
#5
|
|
Registered Member
Join Date: May 2007
Posts: 62
OS: Windows XP,Linux
|
Re: Bash programming question
well I don't know Minix3 specifically, do you have gnu-coreutils installed?
http://www.minix3.org/software/
You will definitely want to get those for any sort of shell scripting!
Edit: I'm almost certain that it comes with gnu-coreutils installed, so forget about that.
Are you familiar with 'sed' 'grep' etc?
__________________
|
|
|
05-17-2007, 01:33 PM
|
#6
|
|
Registered Member
Join Date: May 2007
Posts: 62
OS: Windows XP,Linux
|
Re: Bash programming question
Code:
who|sed -e s/' '/' is ONLINE:'/ -e s/' *'[a-z]*' *'/' Logged in on '/
That should work for the online portion of your script. Ask if you need an explanation or further help.
__________________
|
|
|
05-17-2007, 03:55 PM
|
#7
|
|
Registered Member
Join Date: May 2007
Posts: 62
OS: Windows XP,Linux
|
Re: Bash programming question
also, do you have a small amount of users? and how do they log in?
__________________
|
|
|
05-18-2007, 08:58 AM
|
#8
|
|
Registered Member
Join Date: May 2007
Posts: 5
OS: Vista
|
Re: Bash programming question
That command is working.Sed is a little confusing but i understood it.The users i want to monitor are placed in the file /home/friends.They arent many!For my experiments i write adduser and afterwards i login from another console of minix with the user i just added.
i thought something like that:
last -1 root > log0
last -1 bill > log1
last -1 cate > log2
awk ' {
if($7 == "still")
{ print $1 " is ONLINE: Logged in on " $3" " $4" " $5" " $6 }
else
{ print $1 " last seen on " $3" " $4" " $5" " $6 }
} ' log0
and so on for every user in /home/friends
This outputs what i want but its not dynamic.For example if i added a user in my friends directory i must change this script too.I want the script to look in the /home/friends if you understand me.
__________________
|
|
|
05-18-2007, 03:06 PM
|
#9
|
|
Registered Member
Join Date: May 2007
Posts: 62
OS: Windows XP,Linux
|
Re: Bash programming question
Code:
#!/usr/bin/bash
echo `ls -D /home` > /home/friends
user=1
while [ "$user" -le "`cat /home/friends|wc -w`" ]
do
last -l `awk '{print $'''$user'''}' /home/friends`|awk '{print $1" Last seen on "$3" "$4" "$5" "$6; exit}'
user=`expr $user + 1`
done
rm /home/friends
This script assumes all directories in /home are also usernames.
It should work dynamically as long as home folders are added to /home
Also I'm working in a very limited Minix3 environment so it may not work!
__________________
|
|
|
05-18-2007, 04:55 PM
|
#10
|
|
Registered Member
Join Date: May 2007
Posts: 62
OS: Windows XP,Linux
|
Re: Bash programming question
Code:
477 Packet_Scheduler_Miniport
159 WAN_Miniport_(PPTP)
159 WAN_Miniport_(PPPOE)
159 WAN_Miniport_(L2TP)
159 WAN_Miniport_(IP)
159 Video_Codecs
159 Saitek_Magic_Bus
159 Media_Control_Devices
159 Legacy_Video_Capture_Devices
159 Legacy_Audio_Drivers
159 Direct_Parallel
159 Audio_Codecs
150 AMD_K8_Processor
141 NVIDIA_Network_Bus_Enumerator
141 ECP_Printer_Port
141 Communications_Port
126 NVIDIA_GeForce_7600_GT
041 Realtek_AC'97_Audio1
033 NETGEAR_WG111v2_54Mbps_Wireless_USB_2.0_Adapter
004 \SystemRoot\System0032\Drivers\Sfloppy.SYS
004 \SystemRoot\System0032\Drivers\PCIDump.SYS
004 \SystemRoot\System0032\Drivers\lbrtfdc.SYS
004 \SystemRoot\system0032\DRIVERS\imapi.sys
004 \SystemRoot\System0032\Drivers\i2omgmt.SYS
004 \SystemRoot\System0032\Drivers\Changer.SYS
004 \SystemRoot\System0032\Drivers\Cdaudio.SYS
003 WS2IFSL.SYS
003 Tcpip.SYS
003 Serial.SYS
003 RDPCDD.SYS
003 Rdbss.SYS
003 RasAcd.SYS
003 NetBT.SYS
003 NetBIOS.SYS
003 MRxSmb.SYS
003 mnmdd.SYS
003 kbdhid.SYS
003 IPSec.SYS
003 Fips.SYS
003 AmdK8.SYS
003 AFD.SYS
003 ACPI_Uniprocessor_PC
002 Microsoft_Kernel_System_Audio_Device
001 \SystemRoot\system0032\DRIVERS\rdbss.sys
001 \SystemRoot\System0032\Drivers\NDProxy.SYS
001 \SystemRoot\system0032\DRIVERS\mrxsmb.sys
001 \SystemRoot\system0032\DRIVERS\ipnat.sys
001 Microsoft_WINMM_WDM_Audio_Compatibility_Driver
Just for reference, those are the drivers unable to load, and how many times tried.
__________________
|
|
|
05-20-2007, 06:33 AM
|
#11
|
|
Registered Member
Join Date: May 2007
Posts: 5
OS: Vista
|
Re: Bash programming question
Hi i tried that code but it seems to have a problem that i dont understand.The system doesnt accept the command
user = 'expr $user +1 '
so it doesnt do the loop!But the command according to theory is correct!Isnt it wierd?
I have another problem to solve!I want to find all the
files under the current directory and its subdirs that have a certain pattern.Then
i want to output the name of the files and all the lines in which the pattern is located in that file.
For example an output could be like this:
bash-3.00# findsrc.sh UID
cpio.h:40:#define C_ISUID 0004000 /* Set user ID. */
pwd.h:58:#ifndef _UID_T_DECLARED
pwd.h:60:#define _UID_T_DECLARED
pwd.h:101:#define _PW_KEYBYUID ’\x33’ /* stored by uid */
pwd.h:134:#define _PWF_UID _PWF(2)
tar.h:59:#define TSUID 04000 /* Set UID on execution */
unistd.h:71:#ifndef _UID_T_DECLARED
unistd.h:73:#define _UID_T_DECLARED
uuid.h:30:#ifndef _UUID_H_
uuid.h:31:#define _UUID_H_
uuid.h:59:#endif /* _UUID_H_ */
Any ideas?
Ithought of
read -p pattern
find . -exec grep -l $pattern'{}' \;
find . -exec grep -n $pattern'{}' \;
But that outputs first names and then lines.I want them together.
ls -R maybe and some for ....??
__________________
|
|
|
05-20-2007, 01:55 PM
|
#12
|
|
Registered Member
Join Date: May 2007
Posts: 62
OS: Windows XP,Linux
|
Re: Bash programming question
perhaps try cgrep?
it displays both lines and the file name.
__________________
|
|
|
05-23-2007, 09:18 AM
|
#13
|
|
Registered Member
Join Date: May 2007
Posts: 5
OS: Vista
|
Re: Bash programming question
In minix it doesnt .There is also grep -R but minix doesnt have that command either.
__________________
|
|
|
05-23-2007, 01:43 PM
|
#14
|
|
Registered Member
Join Date: May 2007
Posts: 62
OS: Windows XP,Linux
|
Re: Bash programming question
I wish we were working in the same minix environment. I'm using minix3, but I must be using a different version of the same tools
I'll try and get back to you with a different method.
__________________
|
|
|
07-16-2007, 06:33 AM
|
#15
|
|
Registered Member
Join Date: Jul 2007
Posts: 4
OS: Windows Vista
|
Re: Bash programming question
Hi guys!I am experimenting with minix3 also!But my main interest is its source files!
I was trying to make a system call that (in process manager - pm) returns the structure sigaction .
I want to do it by implementing another function that allows the use of the above system call .
I define the second function like this:
_PROTOTYPE( struct sigaction sigquery, (int _sig) );
where _sig is the type of the signal.
This function should return the sigaction that we have defined in pm.
Any ideas?
__________________
|
|
|
 |
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
All times are GMT -7. The time now is 04:47 AM.