i've tried everything for the past 2 hours to get this working but my experience in shell and programming is limited.
I have a loop
while IFS="," read var1 var2 var3 var4 var5 ; do
statements here...
done < $file
Now the operation inside statement is to read from a text file that has 5 fields as you can see and then use them to create accounts in Linux using bash
useradd $var1 -p var2 -g var3
and so on
I want to make the script to start reading from the second line only, i cant get it working. something like while ifs=, read (from second line) var 1 var 2 var3 etc.
the reason for this is that the file is an exported database from excel to csv so the first line would contain titles like first name dob enrolled etc etc and is not needed
Your help is appreciated
Addition:
Before the users are being created, I have added an if statement and if users meet a condition then they will be created.
if [ "$var5" == "fullyenrolled" ]; then
continue with account creation...
echo "$var1 successfuly created"
else
echo "Sorry user $var1 is not fully enrolled"
fi
the output of the echo is something like
Full name is not fully enrolled
user1 successfuly created
user2 successfuly created
even if i add sed 1d | while IFS= etc etc. it seems that it is still reading the first line this is why im getting the first output like "full name is not fully enrolled"
Use sed to "delete" the first line from the input passed to the while loop
sed 1d $file | while ...
do
your statements here
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With