Home
1.
You have a regular user access to a server, with no root permissions, but you need to create a script that requires root permissions to run - how can you manipulate the system to think that you have root permissions, without a real superuser access?

Linux provides a tool called fakeroot that allows you to run a "fake root shell" that will present you as root and your id as 0, this will make the system believe that you have root access for the current run.

2.
Write a script that receives one parameters (file name) and checks if the file exists or not - If it does, print "Roger that!" else, print "Hey we've got a problem!"

#!/bin/bash
FILE=$1
if [ -f $FILE ];
then
echo "Roger that!"
else
echo "Hey we've got a problem"
fi
3.
Write a script that checks if a file, given as an argument, has more than 10 lines or not, if it does - print "Over 10", else print "Less than 10"
 #!/bin/bash
count=`cat $1 | wc -l`
if [ "$count" -gt "10" ] ;
then
echo "Over 10"
else
echo "Less than 10"
fi
4.
You want to create a backup script called "backupMyFiles" and it will run every hour, how do you make sure that your script is not already running when you run the script - write a short script that will handle this issue and exit with the message "Previous <command> is still running" in case the script is still in the background.
You need to check if your script is currently running in the system -
you can do it with ps
#!/bin/bash
cmd=namedScript
runningProcs=`ps --no-headers -C${cmd}`
count=`echo $runningProcs|wc -l`
if [ $count -gt 1 ]; then
echo "Previous $cmd is still running."
exit 1
fi
5.
create a Fibonacci function (Fn=Fn-1+Fn-2) using awk (until F20).
awk 'BEGIN {
fa=1;
fb=1;
while(++i<=20)
{
print fa;
ft=fa;
fa=fa+fb;
fb=ft
};
exit}'