Home
51.
How can you create a script that will wait for specific output and will act according to it? - for instance, wait for "username:" before sending the username.

Linux provides a tool that "expects" a specific string and sending new commands in response which called "expect".

52.
You want to add logger to your script, how can you send logging messages to the /var/log/messages for your script "MyCoolScript"?

If you want to write to the messages file, you can use the logger tool which is the syslogd api and send log messages - logger -t MyCoolScript Starting Application….

53.
Using perl, write a command that will print all the IPs, Bcasts and Masks configured on the server line by line.
 You need to extract the IPs from the ifconfig first, then run on each line and get the required information -
ifconfig -a | perl -n -l -e '/ addr:([^ ].+)/ and print $1'
               
54.
Write a shell script that checks if a file (as an argument) has write permissions - if its available print "write access approved" else print "no write access".
#!/bin/bash
filename ="$1"
if [ -w "$filename" ]
then
echo "write access approved"
else
echo "no write access";
fi
55.
You have a bash script that does not produce the expected result, how can you debug it?

In order to debug a bash shell script, you need to add "-x" to the shell execute line - "#!/bin/bash -x"