Hi
I was trying to write a simple script really, just to see if the user is root or not. If root -> then execute the next steps (mount windows partition), else exit..
The script i wrote is as follows
Code:
#!/bin/bash
#####Check for UID = 0
clear
ID='id | awk '{print $1;}'|grep "uid=0"'
if [ "$ID" = "uid=0(root)" ]
then
echo; echo "ID is root. [$ID] Continuing ...";echo
else
echo; echo "This script must run as root. Your UID is $ID"
echo "Please su to root and run script again..."
echo "Exiting...";echo
exit
fi
###Mount /dev/hda4
echo "Checking entries in mtab..."
ENTRY= 'cat /etc/mtab | awk '{print $1;}' | grep "/dev/hda4"'
ENTRY_WHERE= 'cat /etc/mtab | awk '{print $1;}' | grep "/home/user/mountpoint"'
if [ "$ENTRY" = "/dev/hda4" ]
then
echo; echo "Already Mounted at [$ENTRY_WHERE] Exiting...";echo
else
echo; echo "Mounting windows from [$ENTRY] at [$ENTRY_WHERE]..."
mount -t vfat /dev/hda4 /home/user/mountpoint/
echo
echo "Mounted..."
exit
fi
The problem is, when I run the commands individually, they work fine, but in the script, i get errors..
Example:
Code:
id | awk '{print $1;}'|grep "uid=0"
gives "uid=0(root)", but when i run it in the script, it gives me something like
---
/home/user/script.sh: line 6: }|grep "uid=0": command not found
id | awk {print
---
The variable doesnt seem to be getting the value at all....
I'm really very new in programing, but certainly not new to Linux...
The script seems fine, no typos, no syntax errors, etc...but i just cant figure out whats wrong...
Any help will be appreciated
king_nothingzzz