• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 598
  • Last Modified:

Korn Shell Script Problem!

I have a problem I have to write a Korn Shell script that takes its input from a flat file and then runs as a batch job every 5am. My questions are how do I get the script to take input from a flat file I have never written a script that way? And second How do I schedual a job with cron to run every 5am?
Thanks!
0
liam_2e
Asked:
liam_2e
1 Solution
 
jlevieCommented:
How you get the input from the file depends to a great degree on what you get from the file and how it is used. A more complete description on what needs to be done would be a big help.

You schedule your script by adding it to the crontab of the appropriate user (probably root) with "crontab -e". To execute a script at 5am the crontab entry would look like:

0 5 * * * /path-to/your-script

See the man pages for crontab for more information.
0
 
newmangCommented:
You can read from a flat file as follows:

#!/usr/bin/ksh
FILE=/home/myfilename
#
# If the address file does not exist there is no point in going on!
if [[ ! -f $FILE ]]
then
    exit 1
fi
#
# Open the file using descriptor 3
exec 3< $FILE
#
# Iterate through each line in the file
while read -u3 LINE
   do
      do what you want with the contents of $LINE
   done
#
# Close the descriptor & file
exec 3<&-
#
# Exit with good result
exit 0

Running each day at 0500 is as per the previous post in this thread.

Cheers - Gavin
0
 
k.kidambiCommented:
If you can post the input (format of the file) and what are all the parameters you are taking from the file and also what do you need to get the output. Then I can probably post the script per your requirement.

Kidambi
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
liam_2eAuthor Commented:
One problem I am going to have is I am passing the input from the text file to a Vignette command and this command will require a variable to have space between ex

transferproject -b computer1:port2134:/pr/34r -o export -t "/ci/34r /ci/324r /ci/34r" -p exportname -l username:password

The problem I am showing is that the stuff in quotes must be read as one variable so I can drop it into the command but there has to be space between the template ids (the ci stuff) for the transferproject command to work. I don't know how to do this if the input variables start and end with a space???
0
 
jlmsCommented:
Confussing...

Post a piece of the file, explain what you need to get, and you'll surely get a nice script.
0
 
k.kidambiCommented:
All you need to do is change the delimiter in the text file where you are calling your vairables.

Here is a sample file that contains your variables.
filename is /yourhome/variables.txt (this file is delimited with ":")

computer1:port2134:/pr/34r" "export:/ci/34r /ci/324r /ci/34r:exportname:username:password

#/bin/ksh

VAR1=`cat variables.txt | awk -F":" '{print $1}'`

similarly you can declare other variables also and then run the follwoing command

transferproject -b ${VAR1}:${VAR2}:${VAR#} -o ${VAR4} -t "${VAR5}" -p ${VAR6} -l ${VAR7}:${VAR8}

Try this out and post your comments here.

Kidambi



0
 
liam_2eAuthor Commented:
Ok here is what the script looks like now, and it works basically it prompts the user for the info that it needs. What I want is to have the info that the user is usually prompted for to be in a text file delimited by ":" although I dont know how to tell the script to read the file and create those variables! I need to have the variable data delimited by ":" because some variables may have some space in them that must be recognize. Well here is my script it is used to transfer vignette projects and templates.

Thanks!!!!!!!!!!!!!!!!!!!



echo "Vignette Project/Template/Data Transfer Script"

sleep 1;

echo " "

echo "Are you going to transfer more than one Template/Record?"
echo "Answer n if you are tranfering a Project y/n: \c"
read transfernum
echo "What is the name of the Source Server that you want to transfer Vignette"
echo "files from?: \c"
read exportmach
echo "What is the name of the Target Server that you want to transfer"
echo "files into?: \c"
read importmach
echo "What is the username to login to the Source Vignette Server?: \c"
read usernm
echo "What is the password to login to the Source Vignette Server?: \c"
read passwrd
echo "What is the Management ID of the Project, or Parent directory"
echo "of the files you would like to transfer?: \c"
read prjnm
echo "What is the Management ID of the Parent directory where the export"
echo "should be imported into?: \c"
read pardir
echo "What would you like to name your exported file?: \c"
read bkpnm


#The logic for a template vs project transfer the top command is template

if [ $transfernum = "y" ]

     then

echo "List the files that you would like transfer. Be sure to"
echo "give the management ID ex /ci/r34 /ci/ty5 and so on.: \c"
read filetrans

     /opt/vignette/vignette/5.5/bin/solaris/transferproject -b $exportmach:18100:$prjnm -o export -t "$filetrans" -p

/var/opt/vignette/$bkpnm -l $usernm:$passwrd;

     else

     /opt/vignette/vignette/5.5/bin/solaris/transferproject -b $exportmach:18100:$prjnm -o export -p

/var/opt/vignette/$bkpnm -l $usernm:$passwrd;

fi
 


#############################################################################################################################


#This is the backup of the Target Server

/opt/vignette/vignette/5.5/bin/solaris/transferproject -b $importmach:18100:$pardir -o export -p /var/opt/vignette/$tbkpnm -l

username:password;




#This is the import of the Targer Server this needs to change to utilize the "z" flag

/opt/vignette/vignette/5.5/bin/solaris/transferproject -b $importmach:18100:$pardir -o import -p /var/opt/vignette/$bkpnm -l

username:password;


echo "Vignette Transfer Complete, Use Vignette Tools to Varify Success"
0
 
liam_2eAuthor Commented:
Ok why does this not work?? I thought this would be the easiest way to write this script but it does not work?? And I  dont know why! I can read the file the id #s are correct the script does run?


###########################################################
# Vignette Project Transfer Script computer1 to  computer2                                               #                
#                                                         #
# NetWeb                                                  #
###########################################################

#!/usr/bin/ksh

echo "Vignette Project/Template/Data Transfer Script"


#############################################################################################################################


IFS=":"
while read projexpmgtid parprojinpmgtid exportnm
do

## do your stuff here


#############################################################################################################################

#The project export

/opt/vignette/vignette/5.5/bin/solaris/transferproject -b computer1:18100:$projexpmgtid -o export -p /var/opt/vignette/$exportnm -l $admin:password1;

#############################################################################################################################

#This is the import

/opt/vignette/vignette/5.5/bin/solaris/transferproject -b computer2:18100:$parprojinpmgtid -o import -p /var/opt/vignette/$exportnm -l admin:password2;


done < /export/home/vigna/Scripts/vgninput.txt
more /export/home/vigna/Scripts/vgninput.txt

echo "Vignette Transfer Complete, Use Vignette Tools to Varify Success"

vnginput.txt has this in it
/pr/3rd:/pr/76y:exporttest


0
 
liam_2eAuthor Commented:
Ok here is where I am now and it is still not working. But I think I am getting closer!
I think my problem is that my variables are not being initialized?? This is what my text file that
contains my varibles looks like.
vnginput.txt has this in it
/pr/3rd:/pr/76y:exporttest


###########################################################
# Vignette Project Transfer Script computer1 to computer2 #                    
#                                                         #
#                                                         #
#                                                         #
###########################################################

#!ksh

echo "Vignette Project/Template/Data Transfer Script"

sleep 1;

echo " "

################################################################################


IFS=":"
while (read projexpmgtid; read parprojinpmgtid; read exportnm)
do

## do your stuff here

################################################################################
 

#The project export

/opt/vignette/vignette/5.5/bin/solaris/transferproject -b computer1:18100:$projex
pmgtid -o export -p /var/opt/vignette/$exportnm -l $admin:password1;

#allow thirty seconds for export to complete
sleep 30;

################################################################################

#This is the import

/opt/vignette/vignette/5.5/bin/solaris/transferproject -b computer2:18100:$parpro
jinpmgtid -o import -p /var/opt/vignette/$exportnm -l admin:password2;


done < /export/home/vigna/Scripts/vgninput.txt
 
more /export/home/vigna/Scripts/vgninput.txt
echo "Vignette Transfer Complete, Use Vignette Tools to Varify Success"
###############NOTE I PUT THIS PIECE IN TO SEE IF MY VARIABLES ARE BEING CREATED
###############AND I DON'T BELIEVE THAT THEY ARE NOTHING IS BEING PRINTED
print $projexpmgtid
print $parprojinpmgtid
print $exportnm
0
 
liam_2eAuthor Commented:
Ok Here is where I am at now. I have been putting in echo statements to see how far the script gets. It runs as far as "IFS all done" so there must be some problem with my while statement??
Thanks
Liam
###########################################################
# Vignette Project Transfer Script devsx022 to devsx025   #                
# Created by Liam Tuohey ltuohey@massmutual.com 6/29/01   #
# NetWeb                                                  #
###########################################################

#!/bin/ksh

echo "Vignette Project/Template/Data Transfer Script Starting"


#############################################################################################################################

VPT_SRC="/export/home/vigna/Scripts/vgninput.txt"
echo "VPT_SRC variable made"
IFS=":"
echo "IFS all done"
while read line
echo "variables created"
do
echo "do start"
projexpmgtid=$(echo $VPT_SRC | awk -F: '{print $1}')  #the first field
parprojinpmgtid=$(echo $VPT_SRC | awk -F: '{print $2}')  #the second one
exportnm=$(echo $VPT_SRC | awk -F: '{print $3}')  #the third one

echo "variable values set"
#############################################################################################################################

#The project export

/opt/vignette/vignette/5.5/bin/solaris/transferproject -b devsx022:18100:$projexpmgtid -o export -p /var/opt/vignette/$exportnm -l admin:easadmin;

echo "export complete"

sleep 30;

#############################################################################################################################

#This is the import

/opt/vignette/vignette/5.5/bin/solaris/transferproject -b devsx025:18100:$parprojinpmgtid -o import -p /var/opt/vignette/$exportnm -l admin:xsw21qaz;
echo "import complete"

done

exit 0
0
 
liam_2eAuthor Commented:
Ok Here is where I am at now. I have been putting in echo statements to see how far the script gets. It runs as far as "IFS all done" so there must be some problem with my while statement??
Thanks
Liam
###########################################################
# Vignette Project Transfer Script devsx022 to devsx025   #                
# Created by Liam 6/29/01   #
# NetWeb                                                  #
###########################################################

#!/bin/ksh

echo "Vignette Project/Template/Data Transfer Script Starting"


#############################################################################################################################

VPT_SRC="/export/home/vigna/Scripts/vgninput.txt"
echo "VPT_SRC variable made"
IFS=":"
echo "IFS all done"
while read line
echo "variables created"
do
echo "do start"
projexpmgtid=$(echo $VPT_SRC | awk -F: '{print $1}')  #the first field
parprojinpmgtid=$(echo $VPT_SRC | awk -F: '{print $2}')  #the second one
exportnm=$(echo $VPT_SRC | awk -F: '{print $3}')  #the third one

echo "variable values set"
#############################################################################################################################

#The project export

/opt/vignette/vignette/5.5/bin/solaris/transferproject -b devsx022:18100:$projexpmgtid -o export -p /var/opt/vignette/$exportnm -l admin:easadmin;

echo "export complete"

sleep 30;

#############################################################################################################################

#This is the import

/opt/vignette/vignette/5.5/bin/solaris/transferproject -b devsx025:18100:$parprojinpmgtid -o import -p /var/opt/vignette/$exportnm -l admin:xsw21qaz;
echo "import complete"

done

exit 0
0
 
liam_2eAuthor Commented:
###########################################################
# Vignette Project Transfer Script comp1 to comp2   #                
# Created by Liam Tuohey  6/29/01   #
# NetWeb                                                  #
###########################################################

#!/bin/ksh

echo "Vignette Project/Template/Data Transfer Script Starting"


#############################################################################################################################

VPT_SRC="/export/home/vigna/Scripts/vgninput.txt"
echo "VPT_SRC variable made"
IFS=":"
echo "IFS all done"
while read line
echo "variables created"
do
echo "do start"
projexpmgtid=$(echo $VPT_SRC | awk -F: '{print $1}')  #the first field
parprojinpmgtid=$(echo $VPT_SRC | awk -F: '{print $2}')  #the second one
exportnm=$(echo $VPT_SRC | awk -F: '{print $3}')  #the third one

echo "variable values set"
#############################################################################################################################

#The project export

/opt/vignette/vignette/5.5/bin/solaris/transferproject -b comp1:18100:$projexpmgtid -o export -p /var/opt/vignette/$exportnm -l admin:4436645;

echo "export complete"

sleep 30;

#############################################################################################################################

#This is the import

/opt/vignette/vignette/5.5/bin/solaris/transferproject -b comp2:18100:$parprojinpmgtid -o import -p /var/opt/vignette/$exportnm -l admin:543673d;
echo "import complete"

done

exit 0
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now