Answer the question
In order to leave comments, you need to log in
How to write everything in one line and output everything to a file?
There is a bash code:
#/bin/sh
inetADD=$1
#GATEWAY=
#DNS1=
NETMASK=255.255.255.128
ip address | grep -v lo | cut -d ' ' -f2 | tr ':' '\n' | awk NF
echo "Enter interface:"
read nameINT
uuid=$($nameINT)
echo -e "NAME=$nameINT\nDEVICE=$nameINT\nBOOTPROTO=static\nUUID=$uuid\nONBOOT=yes\nIPADDR=$1\nNETMASK=$NETMASK" >> /etc/sysconfig/network-scripts/ifcfg-$nameINT
ifdown $nameINT && sleep 3 && ifup $nameINT
if [ "`ping -c 1 -I $nameINT 192.168.1.1`" ] then
echo "Ping GOOD. System EXIT"
exit
else
echo "Reloading the interface"
ifdown $nameINT && sleep 10 && ifup $nameINT
ping -c 1 -I $nameINT 192.168.1.1
echo "ERROR"
fi
echo
or print
well in a format like this:echo -e "#/bin/bash\n.....и так далее из файла" >> /home/script.sh
Answer the question
In order to leave comments, you need to log in
escape all dollars and do cat via DocumentHere:
cat <<EOF >newfile.sh
...
EOF
cat <<EOF>file.sh
#/bin/sh
inetADD=\$1
#GATEWAY=
#DNS1=
NETMASK=255.255.255.128
ip address | grep -v lo | cut -d ' ' -f2 | tr ':' '\n' | awk NF
echo "Enter interface:"
read nameINT
uuid=\$(\$nameINT)
echo -e "NAME=\$nameINT\nDEVICE=\$nameINT\nBOOTPROTO=static\nUUID=\$uuid\nONBOOT=yes\nIPADDR=\$1\nNETMASK=\$NETMASK" >> /etc/sysconfig/network-scripts/ifcfg-\$nameINT
ifdown \$nameINT && sleep 3 && ifup \$nameINT
if [ "\$(ping -c 1 -I \$nameINT 192.168.1.1)" ] then
echo "Ping GOOD. System EXIT"
exit
else
echo "Reloading the interface"
ifdown \$nameINT && sleep 10 && ifup \$nameINT
ping -c 1 -I \$nameINT 192.168.1.1
echo "ERROR"
fi
EOF
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question