LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   I cannot move a my file into my archives directory in my bash scrip (https://www.linuxquestions.org/questions/linux-newbie-8/i-cannot-move-a-my-file-into-my-archives-directory-in-my-bash-scrip-801558/)

Aubrey0406 04-12-2010 09:36 AM

I cannot move a my file into my archives directory in my bash scrip
 
[asy@backnew auto_cron]$ ./journal_ifms
mv: cannot stat `CUSTOMS*': No such file or directory
standard in must be a tty

LouRobytes 04-12-2010 09:40 AM

What's the offending command line in your Script?

Lou

serafean 04-12-2010 09:42 AM

Hi, paste the relevant section of your script. At first glance, this seems as though CUSTOMS might be a variable, but you give it to bash as a path...
Also a wildcard ('*') in a filename isn't a good idea.

Serafean

Aubrey0406 04-13-2010 02:16 AM

mv: cannot stat `CUSTOMS*': No such file or directory standard in must be a tty
 
su - asy -c /home/asy/auto_cron/test1.sql
customs=CUSTOMS*
mv $customs /home/asy/auto_cron/archives/
cat /home/asy/auto_cron/test1.sql | su - asy sqlplus -s / >/dev/null
cd /home/asy/auto_cron/log
date "+begifms%y%m%d_%H%M" > mydate
TEMPFILE=`grep "$mydate" mydate`
export TEMPFILE
touch ${TEMPFILE}
date "+endifms%y%m%d_%H%M" > mydate
TEMPFILE=`grep "$mydate" mydate`
export TEMPFILE
touch ${TEMPFILE}
rm mydate > /dev/null

grail 04-13-2010 02:42 AM

Please explain what this line in your code is supposed to be doing (according to your thoughts):
Quote:

customs=CUSTOMS*

AwesomeMachine 04-13-2010 03:08 AM

In a bash script, anything that executes is in a subshell. So, you must make some statement as to where CUSTOMS is, like this:

CUSTOMS=$HOME/customs

Then the subshell executing mv will know where to look.

And for cd you need a CDHOME= line.

Aubrey0406 04-13-2010 05:01 AM

customs=CUSTOMS*
 
My idea is to make the content of CUSTOMS public / available in order for me to ble to mv it. I have tried export customs and it does not work.

i92guboj 04-13-2010 06:01 AM

Anything that is set in your script will only work in that subshell (and if exported, maybe, for some childs of that subshell). Exporting a variable doesn't make it usable backwards, in parent shells.

If you want the vars of your script to be dumped literally into your current shell you need to source your script using either the "source" command or a dot.

Code:

$ source my_script.sh
# OR
$ . my_script.sh
# Not to be confused with
$ ./my_script.sh # or
$ .my_script.sh

However, if you want to make this permanent, you should rather be using ~/.bashrc or whatever initialization file you prefer for your shell of choice.


All times are GMT -5. The time now is 02:25 AM.