hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Extracting a username from bash script output.
Reply

Forum Jump

Extracting a username from bash script output.

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old
Securing the Dragon.
 
Join Date: Feb 2007
Location: Federal Heights, CO
Posts: 1,807
Question

Extracting a username from bash script output.


I currently have multiple scripts that I use to scan my server for certain files and content. I was wondering if somebody can help me take the output of that script and extract the username for me so that I can run.

Here is the code I am currently using:
Code:
/usr/bin/find /home/*/public_html/ -iname *.bz2 -type f >> /var/log/alog.txt
Here is an example of the output:
Code:
/home/username/public_html/files/csmaps/demomap.tar.bz2
I want to have the script still output the original results but to also extract the username so that I can take the usernames and automatically suspend the accounts using the same bash script.

__________________
-Joe @ Secure Dragon LLC.
+ OpenVZ Powered by Wyvern | KVM | cPanel Hosting | Backup VPSs | LowEndBoxes | DDOS Protection
+ Florida | Colorado | Illinois | California | Oregon | Georgia | New Jersey | Arizona | Texas




Sponsored Links
  #2  
Old
Junior Guru
 
Join Date: Jan 2010
Posts: 202
Try something like

/usr/bin/find /home/*/public_html/ -iname *.bz2 -type f -ls >> /var/log/alog.txt

This will do an ls of the file so using awk you can get the name + filename

e.g.

awk '{ print $6,$11 }' /var/log/alog.txt

HTH

__________________
http://erectvps.com - We care about our customers | OpenVZ US | Level 3 support | Give us try
Twitter: http://twitter.com/erectvps
*New This Week: New SolusVM master VPS*

  #3  
Old
Securing the Dragon.
 
Join Date: Feb 2007
Location: Federal Heights, CO
Posts: 1,807
Awesome! Thank you so much! This code worked perfectly!
Code:
awk '{ print $6,$11 }' /var/log/alog.txt | cut -d/ -f1

__________________
-Joe @ Secure Dragon LLC.
+ OpenVZ Powered by Wyvern | KVM | cPanel Hosting | Backup VPSs | LowEndBoxes | DDOS Protection
+ Florida | Colorado | Illinois | California | Oregon | Georgia | New Jersey | Arizona | Texas


Sponsored Links
  #4  
Old
Securing the Dragon.
 
Join Date: Feb 2007
Location: Federal Heights, CO
Posts: 1,807
Heh, found out that the following works better:
Code:
wk '{ print $5 }' /var/log/alog.txt

__________________
-Joe @ Secure Dragon LLC.
+ OpenVZ Powered by Wyvern | KVM | cPanel Hosting | Backup VPSs | LowEndBoxes | DDOS Protection
+ Florida | Colorado | Illinois | California | Oregon | Georgia | New Jersey | Arizona | Texas


Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can .htaccess call a script (e.g. a bash .sh script)? Kadence Hosting Security and Technology 7 03-26-2008 03:59 PM
bash comman/bash script getbusy Hosting Security and Technology 2 12-25-2004 06:50 PM
Component output script NexDog Programming Discussion 1 09-24-2004 07:32 AM
bash script help innova Hosting Security and Technology 5 06-22-2004 10:54 AM
Script output size CritticAge Web Hosting Lounge 0 09-01-2002 06:22 AM

Related posts from TheWhir.com
Title Type Date Posted
Shellshock-Based Malware Campaign Poses Threat to Mail Servers Web Hosting News 2014-10-28 15:33:56
Could the Shellshock Vulnerability be the Next Heartbleed? Web Hosting News 2014-09-25 13:44:40
Web Hosting Sales and Promos Roundup - December 6, 2013 Web Hosting News 2014-05-23 15:42:37
OpenStack and the AWS API Debate Web Hosting News 2014-05-09 12:40:29
Cisco Researcher Discovers Possible Exploit Vector for DarkLeech Attacks Web Hosting News 2013-04-26 10:19:35


Tags
bash, extract

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
WHT Host Brief Email:

We respect your privacy. We will never sell, rent, or give away your address to any outside party, ever.

Advertisement:
Web Hosting News:
WHT Membership
WHT Membership



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?