Link to home
Start Free TrialLog in
Avatar of TunerML
TunerMLFlag for Jamaica

asked on

Convert Batch Script to Bash

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,
Avatar of MikeOM_DBA
MikeOM_DBA
Flag of United States of America image

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

Avatar of TunerML

ASKER

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?
SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TunerML

ASKER

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.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TunerML

ASKER

Wouldn't have thought to remove the echo or quotes, Thanks guys.