Understanding a Shell Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Understanding a Shell Script
# 1  
Old 03-11-2010
Understanding a Shell Script

Hi Guys,
I am absolutely a newbie to Solaris 8.0. Following is a piece of code in a script (/bin/sh). Can anybody help me in deciphering this ? Please see my questions after the script code -

_____________________________________________________

Code:
/bin/rm -f mycron
crontab -l | grep -v "transferring to a system" | grep -v "Auto deletion of transmitted objects" | grep -v "Dealing with not importable" > mycron

fixpart="/etc/usr/transfer_script  # transferring to a system"
  echo "Specify the frequency in minutes - "
  echo "every 1, 2, 3, or 5 minutes (default every 1 minute) "
  echo  $nn "Frequency [1|2|3|5] ? [1]:" $cc
  read ans
  case $ans in
    2) echo "1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59 * * * *" $fixpart >> mycron
       break ;;
    3) echo "1,4,7,10,13,16,19,22,25,28,31,34,37,40,43,46,49,52,55,58 * * * *" $fixpart >> mycron
       break ;;
    5) echo "1,6,11,16,21,26,31,36,41,46,51,56 * * * *" $fixpart >> mycron
       break ;;
    *) echo "* * * * *" $fixpart >> mycron;;
  esac

_____________________________________________________

1. The crontab part above ?? Smilie
2. What does this mean fixpart="/etc/usr/transfer_script # Auto ...."
3. What is the significance of the variable $fixpart. I did not understand the usage.
Smilie

Basically, can someone explain me this script ?

Thx in advance !

Last edited by pludi; 03-11-2010 at 06:01 AM.. Reason: code tags, please...
# 2  
Old 03-11-2010
Quote:
Originally Posted by angshuman_ag
1. The crontab part above ?? Smilie
2. What does this mean fixpart="/etc/usr/transfer_script # Auto ...."
3. What is the significance of the variable $fixpart. I did not understand the usage.
crontab -l lists all the cron jobs scheduled and grep -v is used not to print the line where the string is present.

The 2nd one its a variable nothing else .

You are assiging a fixpart variable

It is used to echo
# 3  
Old 03-11-2010
Hi amit,
What does this mean
fixpart="/etc/usr/transfer_script # transferring to a system"

There is a "#" before a string and the entire file path and the string are in a quote.
# 4  
Old 03-11-2010
Quote:
Originally Posted by angshuman_ag
Hi amit,
What does this mean
fixpart="/etc/usr/transfer_script # transferring to a system"

There is a "#" before a string and the entire file path and the string are in a quote.

while assigning a variable if it is within " " the shell will consider it a whole . So here its a single string
"/etc/usr/transfer_script # transferring to a system"
# 5  
Old 03-11-2010
fixpart="/etc/usr/transfer_script # transferring to a system"

The fixpart is a variable which is being assigned the value,

/etc/usr/transfer_script # transferring to a system

What the script does is it is adds an entry for the transfer_script to the mycron file with the desired frequency of execution.
# 6  
Old 03-11-2010
Quote:
Originally Posted by Shan_u2005
fixpart="/etc/usr/transfer_script # transferring to a system"

The fixpart is a variable which is being assigned the value,

/etc/usr/transfer_script # transferring to a system

What the script does is it is adds an entry for the transfer_script to the mycron file with the desired frequency of execution.
Hi Shan,
That makes sense. Thanks. So now we have these two lines,

crontab -l | grep -v "transferring to a system" | grep -v "Auto deletion of transmitted objects" | grep -v "Dealing with not importable" > mycron
fixpart="/etc/usr/transfer_script # transferring to a system"

The only common thing is the text "transferring to a system". Does this mean that mycron consists of a job named "transferring to a system" which is executed by the transfer_script file ?

Last edited by angshuman_ag; 03-11-2010 at 11:29 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shall script use and understanding

Below script is called as Reducer, I am not sure how it work, can some expert explain me what this script does as i am a beginner. inputfile: hi hi how are are you code: #!/bin/bash lastkey=""; -- what does this mean, because i saw in debug mode it is taking value as hi count=0;... (13 Replies)
Discussion started by: mirwasim
13 Replies

2. Shell Programming and Scripting

Help understanding the script

Could someone please help me in understanding the code below: #!/usr/bin/ksh Month=`date|cut -c5-7` Day=`date|cut -c9-10` Year=`date|cut -c27-28` Rom2Jul() { case $Month in Feb) Day=$(( $Day+31 ));; Mar) Day=$((... (27 Replies)
Discussion started by: hasn318
27 Replies

3. Shell Programming and Scripting

Trouble understanding shell scripting (mostly wsname)

Am still learning Scripting and I come across a build command that I don't really understand if /local/bin/wsname 2>/dev/null; then base="`/local/bin/wsname`" export base fi if ; then /local/bin/wsname exit 1 fi WSNAME="$base"/ can some one in light me to what... (1 Reply)
Discussion started by: Wpgn
1 Replies

4. Shell Programming and Scripting

Understanding Shell Scripting

Hi Gurus, Im new to Shell scripting. I have a shell script which basically sends an email when called thorugh my ETL tool. Wanted to understand the its functionality in detail. Would be great it any one can explain what exactly the commands to #!/bin/sh # Dummy UUCP rmail command for... (1 Reply)
Discussion started by: r_t_1601
1 Replies

5. Shell Programming and Scripting

Problem with the shell script for understanding

Can Anybody please tell me the meaning of the script: #!/bin/sh str=$@ echo $str | sed 's/.*\\//' exit 0 (6 Replies)
Discussion started by: nixhead
6 Replies

6. Shell Programming and Scripting

shell script behavior is strange or I'm not understanding

Hi I have wrote the small script, where $SRC=$HOME the input file is simple text file having directories in my $SRC on pre line desktop download myfiles games #!/bin/bash FILENAME=$1 ERROR_LOG="$SRC/err.$$.log" while read line do echo "########## strat Gmake $line... (6 Replies)
Discussion started by: the.reverser
6 Replies

7. Shell Programming and Scripting

Need help understanding this script.

Can someone explain what is happening line by line in this script, particularly after the do statement. The script works, it renames all the files in my directory that has a date in the file name. But I would like to know more about it. #!/bin/bash newdate=12-10-1995 for file in *--* do ... (6 Replies)
Discussion started by: Harleyrci
6 Replies

8. Shell Programming and Scripting

Need a better understanding of shell scripts

Need a better understanding of shell scripts (14 Replies)
Discussion started by: sureshkumar4737
14 Replies

9. Shell Programming and Scripting

Understanding a Simple Shell Script

#! /usr/bin/ksh old=$1 new=$2 for file in *.$old ; do mv $file ${file%$old}$new done exit 0 This script i got from the forum. script changes the extension of the files say example a.txt to a.doc b.txt to b.doc c.txt to c.doc d.txt to d.doc this scipt works fine but i am not... (2 Replies)
Discussion started by: vijays3
2 Replies

10. Shell Programming and Scripting

Need help on understanding the Shell and AWK scripts

Hello Friends, I am new to the scripting & have to analyze bunch of regular production scripts. It has .ksh which calls on the .awk script having many functions I need to understand and debug the scripts ASAP Can anybody please let me know as how can I debug, I want to see the flow of code... (3 Replies)
Discussion started by: amberj123
3 Replies
Login or Register to Ask a Question