LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-19-2005, 02:39 PM   #1
rick_james
LQ Newbie
 
Registered: May 2005
Posts: 3

Rep: Reputation: 0
Angry Shell scripting help


omg

I LOVE YOU FOR YOUR HELP Rose_Bud4201!!

I DONT KNOW WHAT I WOULD DO WITHOUT YOU!!

btw a fortune game is just a game where someone types in an age like 21
and it would echo "YOU CAN DRINK LEGALLY!!!" thanks for the help tho!!

Last edited by rick_james; 05-19-2005 at 10:52 PM.
 
Old 05-19-2005, 02:52 PM   #2
win32sux
Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
ahem... is this your homework or something??

 
Old 05-19-2005, 04:47 PM   #3
rose_bud4201
Member
 
Registered: Aug 2002
Location: St Louis, MO
Distribution: Xubuntu, RHEL, Solaris 10
Posts: 927

Rep: Reputation: 30
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 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

Last edited by rose_bud4201; 05-19-2005 at 04:49 PM.
 
Old 05-20-2005, 10:27 AM   #4
rose_bud4201
Member
 
Registered: Aug 2002
Location: St Louis, MO
Distribution: Xubuntu, RHEL, Solaris 10
Posts: 927

Rep: Reputation: 30
Glad to be of help ^_^


Edit: holy cow I'm ridiculous. Remember that not-tested thing? It just bit me in the butt...

Code:
16)
#!/bin/bash
# This sort of needs to be run as a daemon, or in the background.  It's pretty impractical.

shutdown="FALSE"

while [ $shutdown -ne "TRUE" ]; do
    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.
            shutdown="TRUE"
	    su - && ifconfig eth0 down   #This will prompt the user for the root password on whatever console you started the script on.
        fi
    fi
    sleep 300   #5 minutes
done
That's p'bly better...at least the comment makes sense now Still not technically tested, though...

Last edited by rose_bud4201; 05-20-2005 at 10:40 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 03:14 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 04:32 PM
Shell Scripting again yaadhav Linux - Newbie 8 08-04-2005 11:21 AM
shell scripting pcdebb Linux - Newbie 17 11-20-2003 04:49 PM
shell scripting markus1982 Linux - General 2 05-20-2003 08:42 AM


All times are GMT -5. The time now is 07:16 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration