Go Back   Tech Support Forum > Alternative Computing > Other Operating systems

Bash programming question

This is a discussion on Bash programming question within the Other Operating systems forums, part of the Tech Support Forum category. Hello!I am a real noob in bash programming and i would like some help (also i dont know very good


Reply
 
Thread Tools Search this Thread
Old 05-17-2007, 07:53 AM   #1
Registered Member
 
Join Date: May 2007
Posts: 5
OS: Vista



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!

__________________
Bashnoob is offline   Reply With Quote
Old 05-17-2007, 10:19 AM   #2
Registered Member
 
Join Date: May 2007
Posts: 62
OS: Windows XP,Linux



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.

__________________
bkubes is offline   Reply With Quote
Old 05-17-2007, 10:54 AM   #3
Registered Member
 
Join Date: May 2007
Posts: 62
OS: Windows XP,Linux



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.
__________________
bkubes is offline   Reply With Quote
Old 05-17-2007, 12:29 PM   #4
Registered Member
 
Join Date: May 2007
Posts: 5
OS: Vista



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
__________________
Bashnoob is offline   Reply With Quote
Old 05-17-2007, 12:48 PM   #5
Registered Member
 
Join Date: May 2007
Posts: 62
OS: Windows XP,Linux



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?
__________________
bkubes is offline   Reply With Quote
Old 05-17-2007, 01:33 PM   #6
Registered Member
 
Join Date: May 2007
Posts: 62
OS: Windows XP,Linux



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.
__________________
bkubes is offline   Reply With Quote
Old 05-17-2007, 03:55 PM   #7
Registered Member
 
Join Date: May 2007
Posts: 62
OS: Windows XP,Linux



also, do you have a small amount of users? and how do they log in?
__________________
bkubes is offline   Reply With Quote
Old 05-18-2007, 08:58 AM   #8
Registered Member
 
Join Date: May 2007
Posts: 5
OS: Vista



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.
__________________
Bashnoob is offline   Reply With Quote
Old 05-18-2007, 03:06 PM   #9
Registered Member
 
Join Date: May 2007
Posts: 62
OS: Windows XP,Linux



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!
__________________
bkubes is offline   Reply With Quote
Old 05-18-2007, 04:55 PM   #10
Registered Member
 
Join Date: May 2007
Posts: 62
OS: Windows XP,Linux



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.
__________________
bkubes is offline   Reply With Quote
Old 05-20-2007, 06:33 AM   #11
Registered Member
 
Join Date: May 2007
Posts: 5
OS: Vista



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 ....??
__________________
Bashnoob is offline   Reply With Quote
Old 05-20-2007, 01:55 PM   #12
Registered Member
 
Join Date: May 2007
Posts: 62
OS: Windows XP,Linux



perhaps try cgrep?
it displays both lines and the file name.
__________________
bkubes is offline   Reply With Quote
Old 05-23-2007, 09:18 AM   #13
Registered Member
 
Join Date: May 2007
Posts: 5
OS: Vista



In minix it doesnt .There is also grep -R but minix doesnt have that command either.
__________________
Bashnoob is offline   Reply With Quote
Old 05-23-2007, 01:43 PM   #14
Registered Member
 
Join Date: May 2007
Posts: 62
OS: Windows XP,Linux



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.
Attached Thumbnails
Click image for larger version

Name:	Screenshot-minix311_256MB.jpg
Views:	33
Size:	40.4 KB
ID:	13656  
__________________
bkubes is offline   Reply With Quote
Old 07-16-2007, 06:33 AM   #15
Registered Member
 
Join Date: Jul 2007
Posts: 4
OS: Windows Vista



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?

__________________
Wierd is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie saying hello and posing a question
Hi everybody, I've just registered on this forum and would like to say hello to everyone. I'm from Dundee, in Scotland and am interested in many things, including, obviously, computers. I worked in an IT service workshop at Dundee University for four years but left, just as XP was being launched....
mnementh Windows XP Support 1 07-27-2006 02:24 PM
Help With Odd Computer Behaviors
Preface: While you analyze this log please keep in mind that this "HiJackThis" poster has very limited computer knowledge. If you provide me with spyware removal instruction, please relate it in laymen's terms. System: Microsoft Windows XP Media Center Edition Version 2002 Service Pack 2...
Poko Resolved HJT Threads 34 07-16-2006 09:05 PM
newbee drivers question
Zarkonn Joined: 24 Jun 2006 Posts: 1 PostPosted: Sat Jun 24, 2006 12:28 pm Post subject: Newbee Drivers Question Reply with quote Edit/Delete this post Delete this post Hello all..
Zarkonn Driver Support 1 06-24-2006 11:36 AM
Simple Question
Hi! My question is interesting, but not something that requires a lot of programming experience. I have a pretty nice system up in my room with XP installed on it, and a few project programs (illustrator, Flash MX, etc.). I also have a TON of space (or so the records say). THE PROBLEM: The...
PencilThief Windows XP Support 2 02-09-2006 11:48 AM
Afew question
Hi guys, I have afew question. Im about to set up a LAN gaming shop. Im hoping to get sincere help from you guys here so I dont get ripped off by hardwares suppliers. Anyways, here are my question: 1. To keep costs low, Im planning to take out the CD-ROM from every single dekstop. How do...
ExzekieL Windows XP Support 3 01-05-2006 08:21 AM

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is on
Smilies are on
[IMG] code is on
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Post a Question


» Site Navigation
 > FAQ
  > 10.0.0.2


All times are GMT -7. The time now is 12:14 PM.


Copyright 2001 - 2014, Tech Support Forum

Windows 7 - Windows XP - Windows Vista - Trojan Removal - Spyware Removal - Virus Removal - Networking - Security - Top Web Hosts