Solved

Korn Shell Script Problem!

Posted on 2001-06-24
12
580 Views
Last Modified: 2013-12-27
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
Comment
Question by:liam_2e
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 40

Expert Comment

by:jlevie
ID: 6222844
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
 
LVL 4

Expert Comment

by:newmang
ID: 6223135
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
 
LVL 1

Expert Comment

by:k.kidambi
ID: 6225110
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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 

Author Comment

by:liam_2e
ID: 6227648
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
 
LVL 4

Accepted Solution

by:
jlms earned 105 total points
ID: 6228110
Confussing...

Post a piece of the file, explain what you need to get, and you'll surely get a nice script.
0
 
LVL 1

Expert Comment

by:k.kidambi
ID: 6232963
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
 

Author Comment

by:liam_2e
ID: 6238413
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
 

Author Comment

by:liam_2e
ID: 6242673
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
 

Author Comment

by:liam_2e
ID: 6242886
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
 

Author Comment

by:liam_2e
ID: 6245032
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
 

Author Comment

by:liam_2e
ID: 6245045
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
 

Author Comment

by:liam_2e
ID: 6245064
###########################################################
# 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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

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

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

717 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