how to create and access a directory in the same script using variables


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to create and access a directory in the same script using variables
# 1  
how to create and access a directory in the same script using variables

I have a working script that defines the paths using variables which is used to move a rename files that are being archived. Is there a way to create a directory in the path with the date as the name and then reference it when moving the file to it?

Here is what I have tried with no luck....

Code:
#list of prefixes
my @list = qw/CMA CMB CMG CMK CML CMM CMP CMW/;
my $date=`date +%Y%m%d`;
chomp( $date );
mkdir -p /testmisc/import/bts/archive/$date, 0777
mkdir -p /testmisc/import/bts/archive/logs/$date, 0777
 
# directory paths
my $IMPORTBTS = "/testmisc/import/bts";
my $IMPORTARCHIVEBTS = "/testmisc/import/bts/archive/$date";
my $IMPORTBTSLOGS = "/testmisc/import/bts/logs";
my $IMPORTARCHBTSLOGS = "/testmisc/import/bts/archive/logs/$date";
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~ call main
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main();
 
sub main {
do_archive();
exit(0);
 
}
 
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~ Copy Import files to IMPORTARCHIVEBTS
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sub do_archive {
 
if ( ! -d $IMPORTBTS ) {
  print "Directory $IMPORTBTS no found!\n";
  exit( 1 );
} 
 
if (! -d $IMPORTARCHIVEBTS ) {
  print "Directory $IMPORTARCHIVEBTS no found!\n";
  exit( 1 );
}
foreach my $p ( @list ) {
  if ( -e "$IMPORTBTS/$p\_Import.txt" ) {
    my @r = `mv $IMPORTBTS/$p\_Import.txt $IMPORTARCHIVEBTS/$p\_Imp_ARCH_$date.txt`;
    print @r;
    `mv $IMPORTBTSLOGS/$p\_Import_Log.txt $IMPORTARCHBTSLOGS/$p\_Imp_Log_$date.txt`;
    print @r; 
  } 
  else {
    print "$IMPORTBTS/$p\_Import.txt not found!\n";
  }
}
 
return;


Last edited by Franklin52; 03-19-2010 at 06:50 PM.. Reason: Please indent your code and use code tags!!
# 2  
Sorry, I cannot follow this code. This is unix shell not Oracle SQL. There are just too many semi-colons.

It is never necessary or advisible to end a line in unix shell script with a semi-colon.

Please state what Operating System and shell you are using?

If you can, please remove all trailing semi-colons and then re-test and re-post.


Btw (ignoring the semi-colon for the moment) what do you want this command to do?

Quote:
chomp( $date );


After careful thought, this line makes me wonder if this is a normal shell?
Quote:
exit(0);

Time to show my ignorance of Linux .. maybe. What is the command "my"?


I give up. The code posted is unintelligible without context.

Last edited by methyl; 03-20-2010 at 12:27 AM.. Reason: Appended. If you can ...
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #393
Difficulty: Easy
The Portable Operating System Interface (POSIX) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

TCL script to capture range of lines and create two independent variables

Hi I am having a code as stated below module abcd( a , b , c ,da , fa, na , ta , ma , ra , ta, la , pa ); input a , b, da ,fa , na , ta , ma; output c , ra ,ta , la ,pa ; wire a , b , da , fa ,na , ta , ma; // MBIST Structures... (1 Reply)
Discussion started by: kshitij
1 Replies

2. Shell Programming and Scripting

Shell script cannot create directory and move the file to that directory

I have a script, which is checking if file exists and move it to another directory if then mkdir -p ${LOCL_FILES_DIR}/cool_${Today}/monthly mv report_manual_alloc_rpt_A_I_ASSIGNMENT.${Today}*.csv ${LOCL_FILES_DIR}/cool_${Today}/monthly ... (9 Replies)
Discussion started by: digioleg54
9 Replies

3. Shell Programming and Scripting

Shell script to create runtime variables based on the number of parameters passed in the script

Hi All, I have a script which intends to create as many variables at runtime, as the number of parameters passed to it. The script needs to save these parameter values in the variables created and print them abc.sh ---------- export Numbr_Parms=$# export a=1 while do export... (3 Replies)
Discussion started by: dev.devil.1983
3 Replies

4. Homework & Coursework Questions

Create script to add user and create directory

first off let me introduce myself. My name is Eric and I am new to linux, I am taking an advanced linux administration class and we are tasked with creating a script to add new users that anyone can run, has to check for the existence of a directory. if the directory does not exist then it has... (12 Replies)
Discussion started by: pbhound
12 Replies

5. Shell Programming and Scripting

Create variables from directory list problem

I am trying to take a list of directories in a folder and give them a variable name. I have this working with the exception that the shell_exec command wants to place a return. Here is my code which might explain better what I am trying to do: <?php session_start(); $student1=$_SESSION;... (0 Replies)
Discussion started by: robp2175
0 Replies

6. Solaris

create user with RWX access to a specific directory in Solaris 10

I need to create a user account for a developer that will allow him rwx access to all resources in a directory. How can I do that? Thanks (5 Replies)
Discussion started by: gsander
5 Replies

7. Shell Programming and Scripting

how to access variables in a config file inside a shell script

I'm writing a shell script. I want to put the variables in a separate config files and use those inside my script. e.g. the config file (temp.conf)will have the values like mapping=123 file_name=xyz.txt I want to access these variables in temp.conf(i.e. mapping and file_name) from inside the... (7 Replies)
Discussion started by: badrimohanty
7 Replies

8. Shell Programming and Scripting

Listing a directory via a script using variables

In my script I need to list the directory, where the generic name of the files will change, in my test case its set to TEST_*.mqsc. I wrote a small test script as below, but it just does not pip the listing to a file. Any idea why? dir='C:/cygwin/var/log/img/aut/' file=TEST01_*.mqsc ls $dir... (4 Replies)
Discussion started by: gugs
4 Replies

9. UNIX Desktop Questions & Answers

trying to create a script with multiple variables...

I have created a script that prompts the user to enter three variables that are seperated by a space as the delimiter. It then performs a command 3 seperate times for each variable entered. I want the script to llow the user to enter as many variables as they may like and the script to... (5 Replies)
Discussion started by: Italy87
5 Replies

10. Shell Programming and Scripting

How to access the C program variables in shell script

hi I wanted to access the C program variables in shell script. This script is called from the same C program. What are the ways in which i can access variables thankx (3 Replies)
Discussion started by: bhakti
3 Replies

Featured Tech Videos