Your confusion is due to typing issue. Let me clearly explain you.
1.) I try to move files from one directory to another, so used a below command,
The Value for DATAA_DIR and ARCHIVE are,
2.) If i run the above mv command inside my shellscript, im getting the error like
But if i run the same command (i.e:
) outside the shell script, then it works fine.
3.) Instead of using '*' if i used the complete file name (i.e: ABC_20120103) its working fine inside the shell script itself. But i don't want to do that, since n number of files with different date format is present in the directory. So i want to move all the files from data directory to archive directory.
I hope now you are clear with my issue.
Thanks,
Bopty
I think I am clear with your issue. You refuse to see that the backslash character (\) and the slash character (/) are different.
You say that the following:
works on the command line, but don't understand why the following:
doesn't work in your script.
Please execute the following commands exactly and post the results:
On UNIX and Linux systems, the / character separates components in pathnames. On UNIX and Linux systems, the shell uses \ as an escape character; not to separate a directory name from the name of a file in that directory. Therefore, the command:
and the command:
are VERY different. If the first one is working on the command line and the second one is not working in your script; use the first one in your script.
Note that the first one uses the asterisk (*) to expand to a list of files that match the pattern dataABC_*.dat in the directory:
while the second one uses it expand to a list of files that match the pattern ABC_*.dat in the directory:
ls ${DATA_DIR} | grep "ABC" | while read x; do echo $x; mv ${DATA_DIR}/$x ${ARCHIVE}; done
Thanks, Bopty
If the above command works, your current working directory has to be $DATA_DIR. In that case, the commands:
will do the same thing MUCH more efficiently, but it will print all of the filenames before it moves any of them.
If it is important to list each filename just before it is moved, the MUCH less efficient commands:
will still be more efficient than the script you're currently using.
And if there is not any, test it or you get some unwanted action. Example:
If file name generation result is 0 files, then what you are doing ?
You are doing something for filename *ABC*.
And if there is not any, test it or you get some unwanted action. Example:
If file name generation result is 0 files, then what you are doing ?
You are doing something for filename *ABC*.
Good point. From the description of the problem, I was under the impression that there would always be at least one match, but it would be better to verify that there is a match. The test can be inside the loop, or an if could be added before the loop that exits if there is no match. I believe some shells also have a set special built-in utility option that causes patterns that contain wildcard characters to be removed from the list if there are no matching files.
In my script, if there is no match, $PWD/*ABC* will be printed (with the asterisks) and mv will print a file not found diagnostic message and terminate with a non-zero exit status causing the script to return a non-zero exit status.
cat << EOF | telnet alt1.aspmx.l.google.com 25
HELO verify-email.org
MAIL FROM: <check@verify-email.org>
RCPT TO: <test@gmail.com>
quit
EOF
Hello, I'm trying to get the result of that execution, and can not see the result or bring it to a txt ... the direct command in ssh running the result... (5 Replies)
hi all,
i need the shell script for he below requirement
i had the input file as
a_20121217_035120( frmat is a_date_hhmmss)
a_20121217_035128
a_20121217_035456
a_20121217_035767
a_20121217_035178
a_20121217_035189
a_20121217_035220
my output should be
a_20121217_035456... (0 Replies)
Hello. I am a novince at writing shell scripts but here is the question. I have to write a shell script that does the following:
Once executed via crontab, the script should do the following:
a. get date/time stamp in for format 10-MAR-05 and
b. execute shell script my_script.sh (which... (2 Replies)
hI,
Pls consider the following shell script
#!/bin/csh -f
sqlplus tkyte/tkyte <<"EOF" > tmp.csh
set serveroutput on
declare
a number:=5;
begin
dbms_output.put_line( 'a:='||a );
end;
/
spool off
"EOF"
The above script does the followin
1)it connects... (1 Reply)
Iam new to shellscript.
1)How to strart QUERYMANAGER using shellscript.
2)How to put and get messages in MQSeries using shellscripts.
3)iam using local queues .
Thanks lot. (0 Replies)
Folks;
on a unix server I have a mapping file which holds a list mountpoints of all databases and their mountpoints. tab delimited or colon deliminted..I needed to copy the datafiles from the pristine mountpoints to test's mountpoints in this case. I needed to do this by passing sid name using... (18 Replies)
Can I do something like this from a shellscript ?:
ftp 12.34.56.78 <<!
username
password
put a.c
bye
!
It does not go through as the login fails.
Is there any alternative to do the above requirement?
Thanks in advance.
Gowrish (3 Replies)