Solved

unix - how to execute a command through shell

Posted on 2012-03-29
6
311 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: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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Utilizing an array to gracefully append to a list of EmailAddresses
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…

737 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