[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

unix - how to execute a command through shell

Posted on 2012-03-29
6
Medium Priority
?
314 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 42

Expert Comment

by:Meir Rivkin
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
Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

 

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 20

Accepted Solution

by:
simon3270 earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
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…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

650 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