LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-17-2021, 08:52 AM   #1
TravisBrooker
LQ Newbie
 
Registered: Jan 2008
Posts: 22

Rep: Reputation: 0
Problem with my script


Hi all,

there is my script,


#!/bin/bash
#!/bin/sh
. /home/dd/.sshConPrfl

WORK_DIR="directory; export WORK_DIR
SPOOL_DIR="directory"; export SPOOL_DIR
LOG_DIR=directory; export LOG_DIR
scr_name=scr
file_ext=txt
TODAY=`date +"%Y%m%d"`
LOG_DATE=`date +"%Y%m%d%H%M%S"`


sqlplus "my connection" @$WORK_DIR/mytest.sql $SPOOL_DIR/$scr_name"_"$TODAY".tmp"
$WORK_DIR > $LOG_DIR/$scr_name"_"$TODAY.log 2>&1

mv $SPOOL_DIR/$scr_name"_"$TODAY".tmp" $SPOOL_DIR/$scr_name"_"$TODAY"."$file_ext

when i run it in crontab, i saw the error below;
myscript.sh: line 29: sqlplus: command not found
mv: cannot stat ‘/20210317.tmp’: No such file or directory

but it works fine when i am running it with nohup. what could be the reason about why this script is not working with crontab? i checked the permissions and it seems fine. do you have any idea?

thannk you in advance.
 
Old 03-17-2021, 09:13 AM   #2
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
PATH in crontab is usually set to /usr/bin:/bin by default (in Vixie Cron, at least). Either set PATH in the crontab file or (better) use the absolute path to sqlplus.

Last edited by shruggy; 03-17-2021 at 09:20 AM.
 
Old 03-17-2021, 09:19 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,310
Blog Entries: 3

Rep: Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722
Or set the $PATH within the script.
 
Old 03-17-2021, 09:23 AM   #4
TravisBrooker
LQ Newbie
 
Registered: Jan 2008
Posts: 22

Original Poster
Rep: Reputation: 0
Thank you for the answers. if possible could you please show me how to do it?

thank you.
 
Old 03-17-2021, 09:24 AM   #5
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
How to do what? Where is sqlplus installed?
Code:
which sqlplus
 
Old 03-17-2021, 09:26 AM   #6
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,310
Blog Entries: 3

Rep: Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722
Take the output of the following,

Code:
which sqlplus
Then put that in place of "foobar" below:

Code:
#!/bin/sh
. /home/dd/.sshConPrfl

PATH=foobar:/usr/bin:/bin

WORK_DIR="directory; export WORK_DIR
SPOOL_DIR="directory"; export SPOOL_DIR
LOG_DIR=directory; export LOG_DIR
scr_name=scr
file_ext=txt
TODAY=$(date +"%Y%m%d")
LOG_DATE=$(date -d "$TODAY" +"%Y%m%d%H%M%S")


sqlplus "my connection" @$WORK_DIR/mytest.sql $SPOOL_DIR/$scr_name"_"$TODAY".tmp"
$WORK_DIR > $LOG_DIR/$scr_name"_"$TODAY.log 2>&1

mv $SPOOL_DIR/$scr_name"_"$TODAY".tmp" $SPOOL_DIR/$scr_name"_"$TODAY"."$file_ext
What do you have in /home/dd/.sshConPrfl and which distro is this task for?
 
Old 03-18-2021, 04:04 AM   #7
TravisBrooker
LQ Newbie
 
Registered: Jan 2008
Posts: 22

Original Poster
Rep: Reputation: 0
Thank you all,
i did the same as you said.
but i am still getting the error like this below;

myscript.sh: line 29: sqlplus: command not found
mv: cannot stat ‘/myscript_20210318.tmp’: No such file or directory

what could be a problem?
 
Old 03-18-2021, 04:05 AM   #8
TravisBrooker
LQ Newbie
 
Registered: Jan 2008
Posts: 22

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Turbocapitalist View Post
Take the output of the following,

Code:
which sqlplus
Then put that in place of "foobar" below:

Code:
#!/bin/sh
. /home/dd/.sshConPrfl

PATH=foobar:/usr/bin:/bin

WORK_DIR="directory; export WORK_DIR
SPOOL_DIR="directory"; export SPOOL_DIR
LOG_DIR=directory; export LOG_DIR
scr_name=scr
file_ext=txt
TODAY=$(date +"%Y%m%d")
LOG_DATE=$(date -d "$TODAY" +"%Y%m%d%H%M%S")


sqlplus "my connection" @$WORK_DIR/mytest.sql $SPOOL_DIR/$scr_name"_"$TODAY".tmp"
$WORK_DIR > $LOG_DIR/$scr_name"_"$TODAY.log 2>&1

mv $SPOOL_DIR/$scr_name"_"$TODAY".tmp" $SPOOL_DIR/$scr_name"_"$TODAY"."$file_ext
What do you have in /home/dd/.sshConPrfl and which distro is this task for?
Thank you, i did but i got the error as i shared above again.
what sould be the problem? i couldnt understand about it
 
Old 03-18-2021, 04:38 AM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,852

Rep: Reputation: 7310Reputation: 7310Reputation: 7310Reputation: 7310Reputation: 7310Reputation: 7310Reputation: 7310Reputation: 7310Reputation: 7310Reputation: 7310Reputation: 7310
1. use shellcheck to analyze your script
2. show your script, what you posted is just incorrect [syntactically].
3. did you adjust the variable PATH at all?
 
Old 03-18-2021, 05:34 AM   #10
TravisBrooker
LQ Newbie
 
Registered: Jan 2008
Posts: 22

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by pan64 View Post
1. use shellcheck to analyze your script
2. show your script, what you posted is just incorrect [syntactically].
3. did you adjust the variable PATH at all?
Hi, dear friend,
because of privacy i am not able to share all script there,
i couldnt send you private message, if there is a way to share it with you let me know and i can send it to you.
thank you in advance.
 
Old 03-18-2021, 05:39 AM   #11
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,852

Rep: Reputation: 7310Reputation: 7310Reputation: 7310Reputation: 7310Reputation: 7310Reputation: 7310Reputation: 7310Reputation: 7310Reputation: 7310Reputation: 7310Reputation: 7310
In that case you need to check if PATH was set correctly. Also please try shellcheck. Anyway without details hard to go further.
 
Old 03-18-2021, 07:32 AM   #12
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Quote:
Originally Posted by TravisBrooker View Post
Hi, dear friend,
because of privacy i am not able to share all script there,
i couldnt send you private message, if there is a way to share it with you let me know and i can send it to you.
thank you in advance.
No one is asking for the entire script. Pair it down to the essential part that is not working and show us just that running
on its own and the associated error messages
 
Old 03-19-2021, 01:51 AM   #13
TravisBrooker
LQ Newbie
 
Registered: Jan 2008
Posts: 22

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by grail View Post
No one is asking for the entire script. Pair it down to the essential part that is not working and show us just that running
on its own and the associated error messages
Dear my friend,
there is the all script.
thank you.

#!/bin/bash
#!/bin/sh


. /home/user/.sshConPrfl


WORK_DIR=/script/de; export WORK_DIR
SPOOL_DIR=/script/de; export SPOOL_DIR
LOG_DIR=/script/log; export LOG_DIR
scr_name=de_tah
file_ext=txt
TODAY=`date +"%Y%m%d"`
LOG_DATE=`date +"%Y%m%d%H%M%S"`



sqlplus ****/TTS @$WORK_DIR/de_tah.sql $SPOOL_DIR/$scr_name"_"$TODAY".tmp"
$WORK_DIR > $LOG_DIR/$scr_name"_"$TODAY.log 2>&1

mv $SPOOL_DIR/$scr_name"_"$TODAY".tmp" $SPOOL_DIR/$scr_name"_"$TODAY"."$file_ext
 
Old 03-19-2021, 02:42 AM   #14
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,852

Rep: Reputation: 7310Reputation: 7310Reputation: 7310Reputation: 7310Reputation: 7310Reputation: 7310Reputation: 7310Reputation: 7310Reputation: 7310Reputation: 7310Reputation: 7310
and again, how is that PATH variable was set? (which is required to make it work)
 
Old 03-19-2021, 03:02 AM   #15
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,803

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Code:
#!/bin/sh
. /home/dd/.sshConPrfl

PATH=foobar:/usr/bin:/bin

WORK_DIR="directory; export WORK_DIR
SPOOL_DIR="directory"; export SPOOL_DIR
LOG_DIR=directory; export LOG_DIR
scr_name=scr
file_ext=txt
TODAY=$(date +"%Y%m%d")
LOG_DATE=$(date -d "$TODAY" +"%Y%m%d%H%M%S")


sqlplus "my connection" @$WORK_DIR/mytest.sql $SPOOL_DIR/$scr_name"_"$TODAY".tmp"
$WORK_DIR > $LOG_DIR/$scr_name"_"$TODAY.log 2>&1

mv $SPOOL_DIR/$scr_name"_"$TODAY".tmp" $SPOOL_DIR/$scr_name"_"$TODAY"."$file_ext
Might I make a suggestion:

Take that filename construct you have pasted in numerous places:
Code:
$scr_name"_"$TODAY"."
and define it as a new variable:
Code:
FNAME="${scr_name}_${TODAY}"
and plug it in in place of the multiple instances so your two (three? see below) commands become:
Code:
sqlplus "my connection" @${WORK_DIR}/mytest.sql ${SPOOL_DIR}/${FNAME}.tmp
${WORK_DIR} > ${LOG_DIR}/${FNAME}.log 2>&1

mv ${SPOOL_DIR}/${FNAME}.tmp ${SPOOL_DIR}/${FNAME}.${file_ext}
With all those double quotes, you're bound to miss one and get one of those confusing error messages that point to the end of the file. (And the braces keep you out of trouble when combining variables and other text.) You could also "variablize" the script a bit more (i.e., TMPFILE="...", LOGFILE="...", etc.) IMHO, it enhances the readability.

Finally, that "sqlplus" command: Is that wrapped somehow? The line under the sqlplus doesn't make sense. Is there a missing backslash escaping the newline at the end of the sqlplus command string? I.e.:
Code:
sqlplus ... ... ... \
$WORK > your-log-file 2>&1
BTW, if that's the case, you want the "" to be the absolute last character on the line. If it's not you might be escaping a space instead of the new line.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem running an Expect script within a Bash script mbeipi Programming 9 02-10-2018 05:00 AM
Problem running a program/script in the background from a script newbie01.linux Programming 5 03-28-2011 07:28 AM
Bash script problem with ftp session exiting the script early edomingox Programming 5 02-23-2010 05:39 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
PPPD Script problem when cron-scheduling the script andresurzagasti Linux - Networking 0 11-24-2004 02:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration