Solved

Convert Batch Script to Bash

Posted on 2014-01-15
6
517 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
[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
  • 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 200 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
Cloud Training Guides

FREE GUIDES: In-depth and hand-crafted Linux, AWS, OpenStack, DevOps, Azure, and Cloud training guides created by Linux Academy instructors and 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 300 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

624 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