shell unix programming

Posted on 2011-11-01
Last Modified: 2012-08-13
I am not a unix anything but need to figure out what this script does.
Does this  script create a file ( file name ) what the contents of the file would be and also where this script places the file and also if each file overwrites a previous one.
I would love for someone to step me through each line.

if [ $# -ne 2 ] ; then
        echo Usage: $0 'first|second|third|last' code
        exit 1
case $1 in
        first | FIRST )
        second | SECOND )
        third | THIRD )
        last | LAST )
        * )
                echo Unknown number.
                exit 2
cd /usr/tmp
echo $PHONE  $2 > $tempfile
sftp dev@omaha09 <<!
cd /usr/local/tocage
put $tempfile
/usr/bin/rm $tempfile
Question by:Wobbs_pei
    LVL 19

    Accepted Solution

    - The first if/then checks for 2 arguments to the script, and exits if not present
    - The case/esac statement looks at whether argument 1 is one of first/second/third/last (case-insensitive) and assigns the PHONE variable accordingly
    - If it doesn't get a match on any of those, it exits with the error "Unknown number"
    - Then it puts the phone number in $PHONE and also the second argument (looks to be a code) for the script into a temporary file
    - Then it uses secureftp to take that file and put it in /usr/local/tocage on the server omaha09, logging in as the user "dev"
    - Then it cleans up the temporary file that it just copied.
    LVL 31

    Expert Comment

    This code expects two command line parameters, one of first, second, third or last and the filename.

    if [ $# -ne 2 ] ; then
            echo Usage: $0 'first|second|third|last' code
            exit 1
    LVL 19

    Expert Comment

    The file that would be uploaded to the remote server would have one line in it that would look something like this:

    9,16053398788 xxx

    (where "xxx" is the code, or the 2nd argument to the script.  The author however does not put any validation in the script to make sure the code field is accurate)
    LVL 68

    Assisted Solution


    according to the given arguments the script puts one of 4 numbers into a variable.

    It creates a temporary file in /usr/tmp whose name is composed of the process id of the script and the string ".page" by
    echoing the number from above plus the second argument (the usage info says "code") into it.
    The temporary file will be overwritten at each run of the script if it exists, but it's unlikely that this will happen because the filename contains a process id.

    Next, the temporary file is transferred via sftp to a host "omaha09" with a userid of "dev" into the directory /usr/local/tocage there,
    overwriting it if a file with the same name is present (also rather unlikely, because of the process id)

    Finally the temporary file at the local host is removed.

    LVL 9

    Expert Comment

    This has nothing to do with PowerShell, why is this in the PowerShell zone?

    Author Closing Comment

    Thank you both

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
    The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now