Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Bad bash shell script has me stumped...
Message
General information
Forum:
Linux
Category:
Other
Miscellaneous
Thread ID:
00448801
Message ID:
00448967
Views:
18
>>#!/bin/bash
>>cat /root/bbs_scripts/shadow | while read line ; do
>
>I wouldn't do a 'cat' here. I would do a modified 'for a in list' or something like that. Or use awk (gawk, nawk, mawk) or sed.

I've used the 'For ... in..." before but cat seems an easier choice.

>
>> username=""
>> password=""
>> username=`echo $line | cut -d":" -f1`
>> password=`echo $line | cut -d":" -f2`
>
>I'm pretty sure that you don't need to echo the variable here. Since this script is being ran by bash, you should be able to do an escape and just slap the variables in there directly. i.e. - username=`cut -d":" -f1 $line`

While getting the first part of the script to work I tried that.... it didn't work. ???

>
>> echo $username
>> echo $password
>> echo " "

Everything above works ok... the problem is the 'if' section below...

>> if [ "$username" != "" -a "$password" != "" ]; then
>> useradd $username
>> echo $username:$password | chpasswd
>
>Again, I would do away with the echo and just say: chpasswd $username:$password

I'll try that... it looks cleaner. But, I still have to get the 'if' statement syntax correct, and for
the life of me I can't see any errors.

>
>> else
>> echo "$username" >> /tmp/importerror.log
>
>How about losing the "'s? =) Does importerror.log exist?

What 's'?
Yes, the importerror.log exists.

>
>> fi
>>done
Nebraska Dept of Revenue
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform