Solved

unix - how to execute a command through shell

Posted on 2012-03-29
6
307 Views
Last Modified: 2012-04-13
Hello Experts,

I have written the following code:

#!/bin/bash
who | while read x; do
   echo $x | grep '.co.uk' | cut -d' ' -f2;
done

Open in new window


What I want to do is find out if any users have logged in to the system through a ".co.uk" domain.  If they have then I want to run skill -KILL -t <terminal> against that entry.

How do I amend this code to get this working?

Thanks!
0
Comment
Question by:jagku
6 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 37780724
if u run sybase then do the following:

isql -U<username> -P<password> -i<shell_script_path> -o<output_log_file>

make sure u have permissions to run the script
0
 

Author Comment

by:jagku
ID: 37780731
Hi,

No, we don't run sybase.

In a nutshell, I want to do the following:

1) Execute the 'who' command to see who is logged on to the system
2) If the user is logged in from a '.co.uk' domain then log them off using their terminal id (taken from the who command).

I hope that clarifies matters.

Thanks
0
 
LVL 13

Expert Comment

by:stergium
ID: 37780753
you could use pinky

if pinky |grep '.co.uk' ; then echo "uk based. you can do not belong here!" ; fi
hope that helps
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:jagku
ID: 37780795
Hi,

Ok, showing my negligible experience in this!

What I want to do is run a cron which executes every minute.
How can I kick out the terminal (hence skill -KILL) that resonates from a .co.uk address?

Thanks
0
 

Author Comment

by:jagku
ID: 37783138
How, can anyone help?
0
 
LVL 19

Accepted Solution

by:
simon3270 earned 500 total points
ID: 37828289
Something like:

#!/bin/bash
who | grep '\.co\.uk' | while read u trm dt tm hst; do
   skill -kill -t $trm
done

Open in new window


So, we do the grep for .co.uk in one go for the entire who output (the dots are escaped, because "." in a grep regular expression means "any character", and ".co.uk" would match "acoruk.com, for example - we want it to match an actual ".").  Then I use the "read" to split the record into separate fields - $u will contain the first field on the line, $trm the second, $dt the third, $tm the fourth, and $hst the rest of the line.  We know that the terminal ID is the second field, so we use "skill" on $trm.  This will repeat for all lines with ".co.uk" in them.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
question on local dns entry 5 126
unix scripting question 1 89
how to check the status of my java application 8 80
Call Shell Script from Perl Script 6 76
The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now