I got bash script, but when I run it I got some error:
line 54: warning: here-document at line 42 delimited by end-of-file (wanted `EOF')
#!/bin/bash
echo "PODAJ IMIE"
read imie
echo "PODAJ NAZWISKO"
read nazwisko
alias="$imie$nazwisko"
echo "$alias"
while [ 1 ]
do
i=1
if [ `egrep $alias /etc/passwd |wc -l` -gt 0 ]; then i=0
fi
if [ $i -eq 0 ]; then
echo "Uzytkownik o podanym aliasie już istnieje!"
echo "PODAJ INNY ALIAS np. "$alias"1"
read alias
else
echo "PODAJ HASLO"
read -s password
echo "PODAJ NUMER POKOJU"
read pokoj
#adduser --disabled-password --gecos "$imie $nazwisko,$pokoj, ," $alias
adduser --quiet --disabled-password -shell /bin/bash --home /home/$alias --gecos "$imie $nazwisko, $pokoj, , " $alias
echo "$alias:$password" | chpasswd
#echo -e "$haslo\n$haslo\n" | sudo passwd $alias
dir=/home/$alias
mkdir $dir/public_html
mkdir $dir/samba
cd $dir/public_html
mkdir private_html
cat <<EOF >>$dir/.bashrc
echo "alias ps =/bin/ps"
echo "alias ls =/bin/ls"
t=\`date +%F.%H:%M:%S\`
echo "WITAJ\n"
echo "DZISIAJ MAMY:\$t"
echo "TWOJE OSTATNIE LOGOWANIE:" && " lastlog -u \$USER | tail -n 1 | awk '{print \$4" "\$5" "\$6" "\$7" "\$9}'"
EOF
break
fi
done
The EOF
needs to be at the start of a line, and with nothing after (including no whitespace).
Some of the echo
s in that block are suspicions. The text up to the end marker will be copied into the file as-is after variable substitution, not executed - and it doesn't look like you want substitution here.
Try this: (notice the quotes around "EOF"
on the cat
line)
cat <<"EOF" >>$dir/.bashrc
alias ps=/bin/ps
alias ls=/bin/ls
t=$(date +%F.%H:%M:%S)
echo "WITAJ\n"
echo "DZISIAJ MAMY: $t"
echo "TWOJE OSTATNIE LOGOWANIE:" $(lastlog -u $USER | tail -n 1 | awk '{print $4" "$5" "$6" "$7" "$9}')
EOF
The EOF delimiter needs to be aligned in the leftmost column.
Here's what I often do for alignment.
Lots
Of
Indents
cat <<-____________HERE
boo
____________HERE
done
done
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