LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 03-01-2004, 10:31 PM   #1
dianea
LQ Newbie
 
Registered: Mar 2004
Posts: 2

Rep: Reputation: 0
Bash script programming questions


Can someone please help me with my code (these questions are for a school assignment and I am getting parsing errors towards the end of each one when I try and run them).

Much obliged
Diane


2. A system administrator maintains a file with birthdates of all users in /etc/birthdates. The file contains a line for each user, and is updated with the addition of every new user. Each line /etc/birthdates has the following format:
login name: real name: birthdate

Write a shell script to look into this file and send a birthday-congratulation e-mail to relevant users at 1:00 a.m. every day. Make your script as short as possible.

#birthdays – sends the person who is having a birthday that day at 1:00 a congrat email
BEGIN {OFS = “\t”}

#action applied
{
while (($3 = date) && (time = “13:00”))
do
for ($1 = userlist)
mail –s “Congrats on Your Birthday!” userlist
done
}

END{}

#Has bugs


3. Write a bash script that kills all the processes executing a certain command at a certain moment in time. For example, kill all processes running mail. Unless you have a super user privilege, you can kill only your own processes.


#!/bin/sh

PROCESS="mail"
TIME="time"

USER_PID_LIST=`ps -ef | grep $PROCESS \
| grep -v "grep" \
| awk ' { printf( "%s=%s:", $1, $2 ); }' `


# kill -9 $USER_PID
echo "process killed”
done

#Has bugs

4. Write a bash script that takes the name of a directory as an argument and searches the file hierarchy rooted at that directory for zero length files. Write the names of all zero length files to standard output. If there is no option on the command line, have the script delete the file after displaying its name. An -i option on the command line indicates that the script should ask the user for confirmation before deleting the file.

#!/bin/sh
# usage: take the directory as an argument
arg1=$1
grep files arg1
if (files = -size 0[c])
write (file2)
if (arg1=0)
rm –i files
# This is my theory, it needs work


if [ -d $1 -a -d $2 ] #this is code for coping the file to another directory


then : else echo "usage: copynzf dir1 dir2"; fi
x=0; y=0
for i in $1/*
do
if [ -s $i ]
then f=${i##*/}
cp $i $2/$f
let x=x+1
fi
let y=y+1
done
echo "input $y files in $1, output $x non-zero files to $2"
exit
 
Old 03-02-2004, 07:19 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,398

Rep: Reputation: 1964Reputation: 1964Reputation: 1964Reputation: 1964Reputation: 1964Reputation: 1964Reputation: 1964Reputation: 1964Reputation: 1964Reputation: 1964Reputation: 1964
please do not ask for help with homework, it is for you to do, not us.

http://www.linuxquestions.org/rules.php
 
Old 03-02-2004, 12:56 PM   #3
AMMullan
Member
 
Registered: Sep 2003
Location: United Kingdom
Distribution: Ubuntu, Arch
Posts: 437

Rep: Reputation: 30
acid_kewpie's right, been there and it's heaps easier actually doing it.

Although one very handy tip: use set +x at the top of your script, you can find out where it's going wrong.

Good luck
 
Old 03-02-2004, 10:24 PM   #4
dianea
LQ Newbie
 
Registered: Mar 2004
Posts: 2

Original Poster
Rep: Reputation: 0
> This isn't the school supplied code (this is my own code). I just included the questions so if my code (what I'm thinking of anyway) is way off base, someone can tell me. However I will use the set -x command.
Where I am getting the parsing errors is in question #2: on the "mail -s command", on question #3: "kill -9..." and question #4: "let y=y+1". It doesn't say why, it just has a parsing error at the beginning of each one.

P.S. I'm looking for help, not lectures. If you can't help me, don't email me
 
Old 03-03-2004, 12:17 AM   #5
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
The thing is, it's site policy not to help people with their homework. By that, I think it means 'don't provide answers and help people cheat' though.

So, for instance, I'd say to break those scripts down. Run pieces of them through the command line and you may see where they break, rather than having the script just run through and bomb. For instance, with #3, fire up an xterm, as a test and start issuing pieces until you get something like

ps -ef | grep xterm | grep -v grep | awk ' { printf( "%s=%s:", $1, $2 ); }'

and you'll see what's wrong with that one from the output.
 
  


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
bash programming alaios Programming 2 07-23-2005 12:52 AM
issues programming a script in BASH gravesb Linux - Software 1 07-07-2005 01:03 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
bash programming bulliver Programming 2 04-05-2003 09:30 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM


All times are GMT -5. The time now is 07:50 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