Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

shell unix programming

Posted on 2011-11-01
7
Medium Priority
?
336 Views
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
fi
#
#
case $1 in
        first | FIRST )
                PHONE="9,16053398788"
                ;;
        second | SECOND )
                PHONE="9,16054927763"
                ;;
        third | THIRD )
                PHONE="9,16058657899"
                ;;
        last | LAST )
                PHONE="9,16053339843"
                ;;
        * )
                echo Unknown number.
                exit 2
                ;;
esac
#
#
#
tempfile=$$.page
cd /usr/tmp
echo $PHONE  $2 > $tempfile
sftp dev@omaha09 <<!
cd /usr/local/tocage
put $tempfile
quit
!
/usr/bin/rm $tempfile
0
Comment
Question by:Wobbs_pei
6 Comments
 
LVL 19

Accepted Solution

by:
xterm earned 800 total points
ID: 37063428
- 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.
0
 
LVL 31

Expert Comment

by:farzanj
ID: 37063432
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
fi
#
0
 
LVL 19

Expert Comment

by:xterm
ID: 37063442
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)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 200 total points
ID: 37063445
Hi,

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.

wmp
0
 
LVL 9

Expert Comment

by:chrismerritt
ID: 37064722
This has nothing to do with PowerShell, why is this in the PowerShell zone?
0
 

Author Closing Comment

by:Wobbs_pei
ID: 37064904
Thank you both
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…

580 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