Solved

Convert Batch Script to Bash

Posted on 2014-01-15
6
457 Views
Last Modified: 2014-01-17
Hello Experts,

I would like to get this batch code converted to bash,

for /f "tokens=1,2" %i in ('ucommand -list ^| find /i "_ud"') do @command -f %j -user %i -delete

Thanks,
0
Comment
Question by:TunerML
  • 3
  • 2
6 Comments
 
LVL 29

Expert Comment

by:MikeOM_DBA
Comment Utility
Assuming you already converted the "ucommand" and "command" programs, try this:

for line in `ucommand -list | grep -i "_ud"`
do
  i=`echo $line | cut -d" " -f1`
  j=`echo $line | cut -d" " -f2`
  command -f $j -user $i -delete
done  

Open in new window

0
 
LVL 9

Author Comment

by:TunerML
Comment Utility
Any possible way for it to be a one-liner? or would I need to put this in a. sh file and set chmod +x?
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 200 total points
Comment Utility
ucommand -list | grep -i "_ud" | xargs -n2 -sh -c 'command -f $2 -user $1 -delete' argv0

Open in new window


or

ucommand -list | grep -i "_ud" | while read i j ; do command -f $j -user $i -delete; done

Open in new window

0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 9

Author Comment

by:TunerML
Comment Utility
Tried all of the above scripts and encountered errors even with some tweaking though my scripting knowledge in Unix is severely limited.

Okay so a sample output of the ./command -list would be:

"Update information...

Users:
user1 ???_???_UD year.mmdd
user2 ???_???_UD year.mmdd
user3 ???_???_UD year.mmdd
user4 ???_???_UD year.mmdd
user5 ???_???_UD year.mmdd
user6 ???_???_UD year.mmdd
user7 ???_???_UD year.mmdd

Devices:
device1 ???_???_UD year.mmdd
device2 ???_???_UD year.mmdd

..."

What I'm trying to achieve is a script that allows me to run this command for each user;

./command -f ???_???_UD -user user1 -delete
./command -f ???_???_UD -user user2 -delete
./command -f ???_???_UD -user user3 -delete

and so fourth.
0
 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 300 total points
Comment Utility
Works for me:
==> ucommand -list | grep -i "_ud" | while read u f x;do echo "./command -f $f -user $u -delete"; done
./command -f ???_???_UD -user user1 -delete
./command -f ???_???_UD -user user2 -delete
./command -f ???_???_UD -user user3 -delete
./command -f ???_???_UD -user user4 -delete
./command -f ???_???_UD -user user5 -delete
./command -f ???_???_UD -user user6 -delete
./command -f ???_???_UD -user user7 -delete
./command -f ???_???_UD -user device1 -delete
./command -f ???_???_UD -user device2 -delete

Open in new window

PS: Remove the echo and quotes to execute the commands...
0
 
LVL 9

Author Closing Comment

by:TunerML
Comment Utility
Wouldn't have thought to remove the echo or quotes, Thanks guys.
0

Featured Post

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.

Join & Write a Comment

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…
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

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

9 Experts available now in Live!

Get 1:1 Help Now