Solved

unix - how to execute a command through shell

Posted on 2012-03-29
6
305 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
Comment Utility
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
Comment Utility
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
Comment Utility
you could use pinky

if pinky |grep '.co.uk' ; then echo "uk based. you can do not belong here!" ; fi
hope that helps
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:jagku
Comment Utility
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
Comment Utility
How, can anyone help?
0
 
LVL 19

Accepted Solution

by:
simon3270 earned 500 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Utilizing an array to gracefully append to a list of EmailAddresses
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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 gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

6 Experts available now in Live!

Get 1:1 Help Now