File naming format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File naming format
# 1  
Old 04-05-2011
File naming format

Hi,

Code:
su - oracle<<EOC
export PATH=${PATH}:${ORACLE_HOME}/bin
exit
EOC
set `sqlplus -S $user_name/$password@$tns<<EOS
set head off
select min(time),max(time) from products;
exit;
EOS`
var1=$1
var2=$2
su - oracle -c "exp user/pass@localdb file=/oracle/oradata/backup/exp_cal_hist_$var1_$var2_`date +%d_%b_20%y_%H_%M_%S`.dmp log=/oracle/oradata/backup/exp_cal_hist_$var1_$var2_`date +%d_%b_20%y_%H_%M_%S`.log tables=products statistics=none"

The o/p export dump filename displays as below :

exp_cal_hist___05_Apr_2011_17_04_00.dmp

But, here in the above dump file name the values of $var1 and $var2 does not reflect as as per the file name format mentioned below :

exp_cal_hist_$var1_$var2_`date +%d_%b_20%y_%H_%M_%S`.dmp

How it can be solved ?

what is missing ?

Regards
# 2  
Old 04-05-2011
$1 and $2 are arguments for your script. How do you call your script ?
# 3  
Old 04-06-2011
Hi,

$1 and $2 values will get their values from the preceeding select query which are thenafter assigned to var1 and var2 variables.

Regards
# 4  
Old 04-06-2011
I should have read a little more attentively ... You could try this:
Code:
su - oracle -c "$(eval echo "exp user/pass@localdb file=/oracle/oradata/backup/exp_cal_hist_$var1_$var2_`date +%d_%b_20%y_%H_%M_%S`.dmp log=/oracle/oradata/backup/exp_cal_hist_$var1_$var2_`date +%d_%b_20%y_%H_%M_%S`.log tables=products statistics=none")"

If your variables are not substituted you should eval them Smilie
No guarantee here but I look the eval way when I have this kind of trouble
# 5  
Old 04-06-2011
Hi,

'eval' seems not working.

Below is the script which is saved to a particular file (cron_script.sh) using '>>'and this script is scheduled using crontab utility.

Now, every time when the script (cron_script.sh) gets executed as per the schedule, dump file name appears as
exp_cal_hist___06_Apr_2011_15_06_00.dmp

Here as per the below naming format the value of $1 and $2 is not getting reflected in the dump file name.

exp_cal_hist_$1_$2_`date +%d_%b_20%y_%H_%M_%S`.dmp


Code:
echo 'var1=""' >> /tmp/cron_script.sh
echo 'var2=""' >> /tmp/cron_script.sh
echo 'su - oracle<<EOC' >> /tmp/cron_script.sh
echo 'export PATH=${PATH}:${ORACLE_HOME}/bin' >> /tmp/cron_script.sh
echo 'exit' >> /tmp/cron_script.sh
echo 'EOC' >> /tmp/cron_script.sh
echo 'set `sqlplus -S $user_name/$password@$tns<<EOS' >> /tmp/cron_script.sh
echo 'set head off' >> /tmp/cron_script.sh
echo 'select min(time),max(time) from product;' >> /tmp/cron_script.sh
echo 'exit;' >> /tmp/cron_script.sh
echo 'EOS`' >> /tmp/cron_script.sh
echo 'var1=$1' >> /tmp/cron_script.sh
echo 'var2=$2' >> /tmp/cron_script.sh
echo 'su - oracle -c "exp' $user_name'/'$password@$tns 'file=/oracle/oradata/backup/exp_cal_hist_$1_$2_`date +%d_%b_20%y_%H_%M_%S`.dmp log=/oracle/oradata/backup/exp_cal_hist_$1_$2_`date +%d_%b_20%y_%H_%M_%S`.log tables=product statistics=none"' >> /tmp/cron_script.sh

The file name should be as:

exp_cal_hist_25-JUN-09_01-MAR-11_06_Apr_2011_14_26_14.dmp

How it can be solved ?

Regards
# 6  
Old 04-08-2011
I'm sorry but your script and your questions are a little difficult to understand :/
Furthermore I don't have access to your oracle database to reproduce your test (We don't know what's inside your product table)

Did you try by replacing the request by something like this ?
Code:
select 'P1', 'P2' from dual;

Does it work ?
If it works then the problem is in your select statement ...
# 7  
Old 04-08-2011
Hi.

At the very least, you need curly brackets around those variable names:

Code:
...hist_${var1}_${var2}_`date...

to distinguish the variables from the _, as var1_, etc. are valid variable names.

Code:
$ var1_=123
$ echo $var1_
123

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with naming the file

Hi, I have a folder that contains files abc.txt def.txt ....and so on Inside abc.txt, I have @<TRIPOS>MOLECULE 4|Chelerythrine|abcb11_earlyIdentification_Stronginhib_washed_ligprep|sdf|1|dock Inside def.txt, I have @<TRIPOS>MOLECULE... (6 Replies)
Discussion started by: rossi
6 Replies

2. UNIX for Dummies Questions & Answers

Naming file with special characters ?

Hi all, I have a problem with file naming in linux. I have to create a file named like 11/22.csv but shell displays error: no such file or dir. Problem is / character in the file name. I searched unix linux naming concepts and it's restricted in OS. Please tell me if there's any other chance? OS... (3 Replies)
Discussion started by: sembii
3 Replies

3. Shell Programming and Scripting

file naming in a script

#!/bin/bash while read inputline do what="$inputline" echo $what; if ; then exit fi $reextend $what $print ls -a done this is my code i am trying to change all of the file types of a certain directory to another file type but im not all the way there can someone help please (3 Replies)
Discussion started by: domdom110
3 Replies

4. Red Hat

File System Naming Convention

Hi, I am installing a new RHEL 5 application server containing JBOSS along with other specific 3rd party applications. I know that this usually gets installed in /opt but I was thinking of installing these on a new separtate lv / file system instead. i.e. /<my_new_FS_name> rather than... (6 Replies)
Discussion started by: Duffs22
6 Replies

5. Shell Programming and Scripting

File splitting, naming file according to internal field

Hi All, I have a rather stange set of requirements that I'm hoping someone here could help me with. We receive a file that is actually a concatenation of 4 files (don't believe this would change, but ideally the solution would handle n files). The super-file looks like:... (7 Replies)
Discussion started by: Leedor
7 Replies

6. Shell Programming and Scripting

file naming question

Hi, I need some help! I have a file in which i im splitting into 20 different files each called model_001.in model_002.in etc... i would like to make directory for each file using only the name and not the extension so that the directory names are model_001 model_002 etc. ... (8 Replies)
Discussion started by: olifu02
8 Replies

7. Shell Programming and Scripting

#file naming

hi all, Please advise at what circumstance those file will become -rwxr-xr-x 1 psa psa 1969088 Aug 18 2006 #libaa.sl -rwx------ 1 psa psa 2166784 Jul 25 2006 #libcrypto.sl.0.9.7 -rwx------ 1 psa psa 904040 Jul 25 2006 #libxxx.sl -rwx------ 1 psa ... (2 Replies)
Discussion started by: rauphelhunter
2 Replies

8. Shell Programming and Scripting

issue in naming a file

Hi, I want to create a file named 'abc(+1)' and append the data of file 'abc' to it. But getting error as unexpected'(' when i tried to use the following command. cat abc > abc(+1) Is there any other way to include brackets along with +1 in the file name? TIA. (3 Replies)
Discussion started by: vimalr
3 Replies

9. Shell Programming and Scripting

Shell Script for file naming

Hi All, I am looking for a Unix shell script for file naming such that the file names itself as KARAN0001. The 4 digit sequence number must start at 0001 and end at 9999. After 9999 is reached, the number must reset to 0001. Can anyone please help me with that. Thanks & Regards ... (2 Replies)
Discussion started by: karansachdeva
2 Replies

10. Shell Programming and Scripting

naming a file to hostname

I am running a script remotely to another client. after it runs it places the file in /tmp. I need the file in /tmp to be renamed to the local hostname. but when i set the variable it names the file to my local hostname. how do i fix that (4 Replies)
Discussion started by: deaconf19
4 Replies
Login or Register to Ask a Question