Sponsored Content
Top Forums Shell Programming and Scripting Control structures and scripting question.. Post 302369459 by SlapnutsGT on Sunday 8th of November 2009 05:28:53 PM
Old 11-08-2009
Control structures and scripting question..

Hey guys, I'm currently working on a project for comp sci course, and I'm very green to Unix and scripting, and only have a semesters worth of programming knowledge (bare with me! sorry!). What I'm trying to do is make a 'if ... then ... fi' control structure that takes user input and then searches the file where data is going and if the name already exists in first field it prints error msg (cant have two of same name in data file)

So basically its sort a mock inventory auto parts management script, user goes to add new parts, first is prompted to enter name of part ... I then want to compare user input to first field of all entires already in my data file (auto.parts) ... if the part exists print error message, if not continue and add part to data file.

So far I got:
Code:
#bin/sh

echo -n "Please enter auto part name:"
read apname
if [ "$apname" = "$1" ]
then
        echo -n "Part already exists!  Can not enter duplicate parts."
        stop=1
else
        echo -n "Please enter operator's name:"
        read opname
        status="Part Available"
        cdate=""
        bname=""
fi
echo ${apname}:${opname}:${status}:${cdate}:${bname} >> auto.parts
echo "A new auto part has been added to inventory!"

It seems to not be comparing the user input to first field (first field is where auto part name goes i.e <partname>:<stuff>:<stuff>:<etc..>), it just ignores the statement and continues on ... allowing me to enter 100 Brake:etc:etc:etc lines if I wish too, which it shouldn't!. I'm almost positive i'm using wrong syntax in my if [statement]. ANY help, or finger pointing me to a great website for beginners would be MUCH appreciated!!

Thanks guys!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

another scripting question

I am writing a script that will identify the oldest file in a directory. Here's the syntax: #!/bin/ksh cd directory chmod 777 * ls -r -1t > file1 sed -n -e "1P" < file1 > file2 So my problem is, now I have file2, which contains the name of the oldest file in the directory. How do I use,... (1 Reply)
Discussion started by: kristy
1 Replies

2. Shell Programming and Scripting

another scripting question

Hello I am working on cleaning up permissions on Oracle mountpoints and datafiles in unix. I am looking for a script or a scripting idea to 1st. 1. grep for owner oracle 2. ensure its a directory owned for oracle 3. chmod 750 on the oracle owned directory. 4. grep for oracle files, etc... (3 Replies)
Discussion started by: jigarlakhani
3 Replies

3. Shell Programming and Scripting

scripting question

I'm new to shell scripting and am having a problem trying to do something in C shell. I want to write a script that will input something instead of a user doing it. For example, using the command 'write' the user is supposed to type something to be sent to another user. I want a script to be able... (3 Replies)
Discussion started by: batmike
3 Replies

4. UNIX for Dummies Questions & Answers

FTP access & control question

Folks; I need some help with these: 1. understanding how to control access rights and manage visibility using FTP in Solaris, in other words, I need to use FTP in Solaris to be able to give some users access to add/modify data to/from the UNIX server. 2. How can i control the space allowed for... (2 Replies)
Discussion started by: Katkota
2 Replies

5. UNIX for Dummies Questions & Answers

Scripting question

folks; I have a script to remove any files that older than 14 days then move any files that younger than 7 days to another directory. but for some reason it doesn't move the files, when i do it manually it works but not through the script. i tried 2 different ways in writing the move part but it... (6 Replies)
Discussion started by: Katkota
6 Replies

6. Linux

SSH remote control question

I am pretty new to linux so forgive me for asking a basic question :P I am using SSH to control 40 machines. What i am trying to do is remotely bash a shell script on each machine. I am using a for loop to bash every script, code as follows. code in host machine runallworkers.sh: ... ... (2 Replies)
Discussion started by: mgsolid
2 Replies

7. Shell Programming and Scripting

Scripting question

Preview of command prompt f ---> to start ferret q----> to stop ferret asp@nex:~$ f NOAA/PMEL TMAP FERRET v6.82 Linux 2.6.18-308.8.2.el5PAE 32-bit - 08/03/12 3-Dec-12 16:44 yes? go my.jnl yes?column=4/skip=1/type=num,text ............filename.txt ---... (4 Replies)
Discussion started by: nex_asp
4 Replies

8. Shell Programming and Scripting

Scripting question

hi all, I am writing a script and beginner in shell scripting. I have tried the below script. could you please check and let me know whether the below scirpt is correct. Unix details : HP Unix Input file. cat input.txt | tail -4 HTS40002.W1978.PROM HTS40003.W1978.PROM... (17 Replies)
Discussion started by: arun888
17 Replies

9. UNIX for Advanced & Expert Users

Question for expert only in Access control list

If I'm the admin for the financial system and I want to configure authorization pf file system permission.Also, The first rule is that Managers and clerks can read and write billings for all cases. The second rules is that Paralegals and administrative assits can read and write billings only on... (2 Replies)
Discussion started by: mecnio
2 Replies

10. SCO

Emacs Question; Control-G Not Working

Hi! I am using Emacs 22.3.1 and the Control-G command will not work to cancel. I took my init.el file out of the mix and it stills does not work. I am not sure when I upgraded from 20.4 to 22.3.1, if it worked, but it certainly does not now. Any thoughts... (6 Replies)
Discussion started by: trolley
6 Replies
MAILDROPEX(7)						      Double Precision, Inc.						     MAILDROPEX(7)

NAME
maildropex - maildrop filtering language examples SYNOPSIS
$HOME/.mailfilter, $HOME/.mailfilters/* DESCRIPTION
If $HOME/.mailfilter exists, filtering instructions in this file will be carried out prior to delivering the message. The filtering instructions may instruct maildrop to discard the message, save the message in a different mailbox, or forward the message to another address. If $HOME/.mailfilter does not exist, or does not provide explicit delivery instructions, maildrop delivers the message to the user's system mailbox. The files in $HOME/.mailfilters are used when maildrop is invoked in embedded mode. EXAMPLES
Take all mail that's sent to the 'auto' mailing list, and save it in Mail/auto. The 'auto' mailing list software adds a "Delivered-To: auto@domain.com" header to all messages: if (/^Delivered-To: *auto@domain.com$/) to Mail/auto After the to command delivers the message, maildrop automatically stops filtering and terminates without executing the subsequent instructions in the filter file. Take all mail from boss@domain.com about the current project status, save it in Mail/project, then forward a copy to John: if (/^From: *boss@domain.com/ && /^Subject:.*[:wbreak:]project status[:wbreak:]/) { cc "!john" to Mail/project } Note that it is necessary to use a backslash in order to continue the if statement on the next line. Keep copies of the last 50 messages that you received in the maildir directory 'backup'. NOTE: 'backup' must be a maildir directory, not a mailbox. You can create a maildir using the maildirmake command. cc backup `cd backup/new && rm -f dummy `ls -t | sed -e 1,50d`` Put this at the beginning of your filter file, before any other filtering instructions. This is a good idea to have when you are learning maildrop. If you make a mistake and accidentally delete a message, you can recover it from the backup/new subdirectory. Save messages that are at least 100 lines long (approximately) into Mail/IN.Large:: if ( $LINES > 100 ) to Mail/IN.Large Send messages from the auto mailing list to the program 'archive', using a lock file to make sure that only one instance of the archive program will be running at the same time: if (/^Delivered-To: *auto@domain.com$/) dotlock "auto.lock" { to "|archive" } Check if the Message-ID: header in the message is identical to the same header that was recently seen. Discard the message if it is, otherwise continue to filter the message: `reformail -D 8000 duplicate.cache` if ( $RETURNCODE == 0 ) exit The reformail[1] command maintains a list of recently seen Message-IDs in the file duplicate.cache. Here's a more complicated example. This fragment is intended to go right after the message has been filtered according to your regular rules, and just before the message should be saved in your mailbox: cc $DEFAULT xfilter "reformail -r -t" /^To:.*/ getaddr($MATCH) =~ /^.*/; MATCH=tolower($MATCH) flock "vacation.lock" { `fgrep -iqx "$MATCH" vacation.lst 2>/dev/null || { echo "$MATCH" >>vacation.lst ; exit 1 ; } ` } if ( $RETURNCODE == 0 ) exit to "| ( cat - ; echo ''; cat vacation.msg) | $SENDMAIL" This code maintains a list of everyone who sent you mail in the file called vacation.lst. When a message is received from anyone that is not already on the list, the address is added to the list, and the contents of the file vacation.msg are mailed back to the sender. This is intended to reply notify people that you will not be answering mail for a short period of time. The first statement saves the original message in your regular mailbox. Then, xfilter[2] is used to generate an autoreply header to the sender. The To: header in the autoreply - which was the sender of the original message - is extracted, and the getaddr[3] function is used to strip the person's name, leaving the address only. The file vacation.lst is checked, using a lock file to guarantee atomic access and update (overkill, probably). Note that the backslashes are required. If the address is already in the file, maildrop exits, otherwise the contents of vacation.msg are appended to the autoreply header, and mailed out. Note An easier to make a vacation script is with mailbot(1)[4]. Here's a version of the vacation script that uses a GDBM database file instead. The difference between this script and the previous script is that the previous script will send a vacation message to a given E-mail address only once. The following script will store the time that the vacation message was sent in the GDBM file. If it's been at least a week since the vacation message has been sent to the given address, another vacation message will be sent. Even though a GDBM database file is used, locking is still necessary because the GDBM library does not allow more than one process to open the same database file for writing: cc $DEFAULT xfilter "reformail -r -t" /^To:.*/ getaddr($MATCH) =~ /^.*/; MATCH=tolower($MATCH) flock "vacation.lock" { current_time=time; if (gdbmopen("vacation.dat", "C") == 0) { if ( (prev_time=gdbmfetch($MATCH)) ne "" && $prev_time >= $current_time - 60 * 60 * 24 * 7) { exit } gdbmstore($MATCH, $current_time) gdbmclose } } to "| ( cat - ; echo ''; cat vacation.msg) | $SENDMAIL" This script requires that maildrop must be compiled with GDBM support enabled, which is done by default if GDBM libraries are present. After you return from vacation, you can use a simple Perl script to obtain a list of everyone who sent you mail (of course, that can also be determined by examining your mailbox). SEE ALSO
maildrop(1)[5], maildropfilter(7)[6], reformail(1)[1], mailbot(1)[4], egrep(1), grep(1), sendmail(8). AUTHOR
Sam Varshavchik Author NOTES
1. reformail [set $man.base.url.for.relative.links]/reformail.html 2. xfilter [set $man.base.url.for.relative.links]/maildropfilter.html#xfilter 3. getaddr [set $man.base.url.for.relative.links]/maildropfilter.html#getaddr 4. mailbot(1) [set $man.base.url.for.relative.links]/mailbot.html 5. maildrop(1) [set $man.base.url.for.relative.links]/maildrop.html 6. maildropfilter(7) [set $man.base.url.for.relative.links]/maildropfilter.html Courier Mail Server 08/30/2011 MAILDROPEX(7)
All times are GMT -4. The time now is 03:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy