Solved

unix - how to execute a command through shell

Posted on 2012-03-29
6
308 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
CMD shell elevation.js 4 64
Replace a tag with sed 2 49
VBA Shell can't Find Word document 11 94
Determine Who is Runnig my Bash Shell Script 4 80
This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

773 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