Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Convert Batch Script to Bash

Posted on 2014-01-15
6
Medium Priority
?
564 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
ID: 39783711
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
ID: 39783826
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 800 total points
ID: 39783929
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
LVL 9

Author Comment

by:TunerML
ID: 39785136
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 1200 total points
ID: 39785568
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
ID: 39788423
Wouldn't have thought to remove the echo or quotes, Thanks guys.
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 …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
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 …
Suggested Courses

972 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