How to retrieve the value of variable in shell script which is called by crontab


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to retrieve the value of variable in shell script which is called by crontab
# 1  
Old 08-03-2010
How to retrieve the value of variable in shell script which is called by crontab

There are two files one is shell script (sample.sh) and another is configuration file (sampl_conf.cfg)

configuration file contains one variable $FTP_HOME. the value of this variable vaires for user to user. If user is say jadoo then value is /home/jadoo/ftp/, for user1 - /home/user1/ftp. The value can be seen at command prompt by typing "echo $FTP_HOME".

In shell script $FTP_HOME variable is used to find out some old file in that path (/home/jadoo/ftp).

Shell scripts reads the configuration file line by line and assing $FTP_HOME variable to another variable say "path"

Code:
 
#!/bin/sh
...........
    path=`echo $LINE | cut -d" " -f1`
    duration=`echo $LINE | cut -d" " -f2`
    filename=`echo $LINE | cut -d" " -f3`
    path="$path"
path=`eval echo $path`
    if [ "$filename" != "" ] ; then
         `find $path/$filename -type f -mtime $duration >> $tmpfile;`

Now find should search mentioned file for specific duration in $FTP_HOME directory, but it unable to replace the $FTP_HOME variable by its value.
below error displays on terminal

find: stat() error /log*: No such file or directory

Sample configuration file

Code:
 
$FTP_HOME +15 log*

thanks in advance.

---------- Post updated at 12:26 PM ---------- Previous update was at 12:02 PM ----------

any kind of help will be appricated.
# 2  
Old 08-03-2010
Where is FTP_HOME set? Because cron jobs do not read any login scripts (/etc/profile, ~/.profile, ...)
# 3  
Old 08-03-2010
is there any way to find out where $FTP_HOME is set??

OS - Sun Solaries
# 4  
Old 08-03-2010
If it's set system-wide for all users, look in /etc/profile or any scripts invoked by ~/.profile. Depending on the shell you might have to check /etc/*bash*, ~/.bashrc, ~/.login too.
# 5  
Old 08-03-2010
Unable to understand the requirement completely, but as far as the config file parameter,
you have to source to file within "sample.sh"

you sample code is also incomplete;
after aligning the code, I found this

Code:
#!/bin/sh
path=`echo $LINE | cut -d" " -f1` 
duration=`echo $LINE | cut -d" " -f2`
filename=`echo $LINE | cut -d" " -f3`
path="$path"
path=`eval echo $path`

if [ "$filename" != "" ] ; then
	`find $path/$filename -type f -mtime $duration >> $tmpfile;`

which is incomplete.

In addition, reassigning path to the same value doesn't make any sense.
there is no need to run the find command in another shell.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to pass the config file lines as variable on the respective called function on a script

I want to make a config file which contain all the paths. i want to read the config file line by line and pass as an argument on my below function. Replace all the path with reading config path line by line and pass in respective functions. how can i achieve that? Kindly guide. ... (6 Replies)
Discussion started by: sadique.manzar
6 Replies

2. Shell Programming and Scripting

Passing variable from called script to the caller script

Hi all, Warm regards! I am in a difficult situation here. I have been trying to create a shell script which calls another shell script inside. Here is a simplified version of the same. Calling Script. #!/bin/ksh # want to run as a different process... (6 Replies)
Discussion started by: LoneRanger
6 Replies

3. Shell Programming and Scripting

Passing the value of variable which is read from command line in called script

Hi, I am calling a Perl script in my shell script. When Perl script is executed it asks for a answer to be entered by user from terminal. How can i pass that value from my shell script ?? I know I can change perl script to default the answer but i dont have access to do that so only option i... (5 Replies)
Discussion started by: varun22486
5 Replies

4. Shell Programming and Scripting

DBUS_SESSION_BUS_ADDRESS for script called from crontab.

Hi, I'm writing a Bash script for wallpaper clocks which works fine on the command line but needs to be run every minute from a crontab entry so the time gets changed on the wallpaper (the wallpaper gets rebuilt every minute so the current weekday, date, month, hour, and minute become part of... (4 Replies)
Discussion started by: gencon
4 Replies

5. Shell Programming and Scripting

Can a shell variable be called in a cobol program

Hi All, I have a file which sets all the variables on unix , based on the hostname. Currently these variables are hardcoded in the cobol programs.I was wondering if unix variables can be used in Cobol programs ? Example : I have a variable $SHTEMP which is set based on the following : Prod... (2 Replies)
Discussion started by: nua7
2 Replies

6. Shell Programming and Scripting

environment variable in shell script called through crontab

Please help me on below.. https://www.unix.com/shell-programming-scripting/141533-retrieve-value-environment-variable-shell-script-called-crontab.html#post302442024 I'm still here. I can still see you! (0 Replies)
Discussion started by: jadoo_c2
0 Replies

7. Shell Programming and Scripting

Retrieve the value of environment variable in shell script which called from crontab

There are two files one is shell script (sample.sh) and another is configuration file (sampl_conf.cfg) configuration file contains one variable $FTP_HOME. the value of this variable vaires for user to user. If user is say jadoo then value is /home/jadoo/ftp/, for user1 - /home/user1/ftp. The... (0 Replies)
Discussion started by: jadoo_c2
0 Replies

8. Shell Programming and Scripting

Retention of Variable Value when a script is called by different processes in parallel- Linux 2.6.9

Hi, I have a generic FTP script which will be called by 28 different processes in parallel (through a GUI tool) may or may not be at the exact moment (there could be a delay of about a minute or so). ./FTP.ksh 1 (1 through 28) This script after importing file from remote m/c... (1 Reply)
Discussion started by: dips_ag
1 Replies

9. Shell Programming and Scripting

How to return the value from the called shell script to the calling sh script

Hi all, I have two ksh scripts #sample1.sh #!/bin/ksh . ./sample2.sh echo $fileExist #sample2.sh #!/bin/ksh func() { i=1 return $a } func echo $? Here how should I return the value of sample2.sh back to sample1.sh? Thanks in advance. (2 Replies)
Discussion started by: gp_singh
2 Replies

10. Shell Programming and Scripting

gzip in shell script called by cron

I'm puzzled by this one. I hope you can explain it to me. I have a ksh shell script that gzips a file among other things. This works perfectly fine when the script is manually run through a shell. However, when the same script is run through cron, it does everything correctly, but it will... (2 Replies)
Discussion started by: hbau419
2 Replies
Login or Register to Ask a Question