rose_bud4201 |
05-19-2005 03:47 PM |
This is _unquestionably_ homework, which means we're really not supposed to answer....And really, you should be able to get at least some of these - they're one-liners for the most part, and google will give you the answer if you take the time to look!
However, I'm bored :p So here we go:
Code:
1) for i in `ls /home/`; do user=${i%'/'}; space=`du -sh /home/$i`; space=${space:0:4}; if grep -q $user /etc/passwd; then echo -e "$user: $space\n"; fi; done
2) Haven't the faintest
3) Haven't the faintest
4) alias mm="cat /etc/fstab | egrep '(ext2|ext3)'"
5) set | grep -i bash | sort
6)
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Error, I need a numeric grade!"
exit;
fi
if [ "$1" -lt 65 ]; then
grade="F";
elif [ "$1" -lt 70 ]; then
grade="D";
elif [ "$1" -lt 80 ]; then
grade="C";
elif [ "$1" -lt 90 ]; then
grade="B";
elif [ "$1" -le 100 ]; then
grade="A";
fi
echo $grade
7)
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Error, give me a file to compress!"
exit;
fi
$filename
gzip -v $filename 2>temp
cat temp | awk '{print $2}'
rm temp
8) Haven't the faintest
9)
#!/bin/bash
echo -e "1: 272\n2: 077\n3: 027\nChoice: "
read choice;
if [ "$choice" -eq "1" ]; then
umask 272;
elif [ "$choice" -eq "2" ]; then
umask 077;
elif [ "$choice" -eq "3" ]; then
umask 027;
fi
echo "Umask set."
10) mke2fs /dev/fd0
11)
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Error, I need a device name or mount point!"
exit;
fi
umount $1 1>/dev/null 2>/dev/null #Really don't care, as long as it's unmounted
fsck $1
12) This one's sort of pointless...it's the entire purpose of the adduser command O_o
#!/bin/bsah
if [ $# -ne 2 ]; then
echo "Usage <scriptname> username password"
exit;
fi
username=$1;
password=$2;
useradd -p $password $username
13) Haven't the faintest
14) I can't install rpms, so this one's not happening
15) I'm unsure why this would be a script...
wget ftp://ftp.cac.washington.edu/pine/pine.tar.gz
16) I think you mean eth0 ....??
#!/bin/bash
# This sort of needs to be run as a daemon, or in the background. It's pretty impractical.
currenthour=`date +%H`
if [ "$currenthour" -ne "21 ]; then
exit
else
currentminute=`date +%M`
if [ "$currentminute" -le "05" ]; then #Got to allow + or - 5 minutes, that's my sleep time.
su - && ifconfig eth0 down #This will prompt the user for the root password on whatever console you started the script on.
fi
fi
17)
echo "The server will be down for maintainence from 13:00 to 15:00 hours today."; /sbin/shutdown -h 13:00
(The "coming back up at 15:00" part is a little hard to automate, the computer being off and all ;-) )
18)
#!/bin/bash
echo "Enter your birthday as Month Day, i.e. May 19"
read birthday
now=`date +%s`
birthdaysec=`date -d "$birthday" +%s`
if [ "$birthdaysec" -gt "$now" ]; then
let numofsec=$birthdaysec-$now
else
let numofsec=$now-$birthdaysec
fi
echo "Number of seconds until your birthday: $numofsec"
19) WTF is a fortune game???
20)
i=0; while [ "$i" -lt "10458" ]; do echo $i; let i=$i+1; done;
If they don't work/destroy your system, don't blame me...I tested most of them, but not all (the fsck one, the umask one, the pine one, the ech0 one, the shutdown one...I take it back, there's quite a few that I didn't test).
They're not bulletproof, they make some assumptions (esp. the birthday one), they _probably_ won't segfault anything...but don't try them if you're not very sure how to fix what they may do (ESPECIALLY the fsck one)! Also, if you don't understand a command, look it up first ('man mysteryCommand' ought to be your immediate first resource, Google your second) before asking about it...if I know there's a man page available and you don't demonstrate that you've at least attempted to read it, you won't be getting a very helpful answer back ;)
Cheers
|