Some problem with script.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Some problem with script.
# 8  
Old 08-01-2006
not initialized? can you please elaborate futher?

beside's the $logname is define as...

Code:
while ($logname = readdir( DIR ))
{
    if ($logname =~ m/not_terminated/ || $logname =~ /^\./)
    {
        ; # leave this file alone
    }

    else
    {
        @fields = split( /\./, $logname );

        $_ = $fields[1]; # get roll over time

        #  $1        $2    $3
        #  Y Y Y Y   M M   D D
        /(\d\d\d\d)(\d\d)(\d\d)/;

        $year = $1 - 1900;
        $month = $2 - 1;
        $day = $3;

        $time_of_log = timelocal( 0, 0, 0, $day, $month, $year );

        if ($time_of_log < $time_expired)
        {
            # delete file
            $filename = $dirname . "/" . $logname;
            unlink $filename;
        }
    }
}

closedir( DIR );

Moderator's note: 12yearold, please be sure to put your code within code tags. Makes it easier to read.

Last edited by vino; 08-01-2006 at 01:51 AM.. Reason: Added code tags
# 9  
Old 08-01-2006
The $1 $2 $3 varaibles are returned by executing a regex with /() () ()/ in it.

Each separate (regex) becomes $1 or $2 according to the order the results are found.

Your code is not finding the regex, ie. the files are not there, or not named the way the code expects. So $1, $2, $3 are not defined.
# 10  
Old 08-01-2006
you were SPOT ON!!!
solid find bro....

now i have one slight problem...

is my filename is 20060726160000.20060727160000.xxxxxxxxxx
and i would just like to use the 20060726 part, so i just include in the brackets... but attach no variables to it?

# $1 $2 $3
# Y Y Y Y M M D D
/(\d\d\d\d)(\d\d)(\d\d)(\d\d\d\d).(\d\d\d\d)(\d\d)(\d\d)(\d\d\d\d).//;


would that be okay?
# 11  
Old 08-01-2006
hmmm...tried... it doesn't work...
would appreciate some help please....
# 12  
Old 08-01-2006
Come on. Learn some Perl first and look for some of the beginner's tutorials online first. Don't really expect to use Perl effectively without any reading. It is not going to work.

Code:
my ($y, $m, $d);
my $str = "200610240000.abcdefghijkl";
if ($str =~ /^(\d{4})(\d{2})(\d{2})/) {
    ($y, $m, $d) = ($1, $2, $3);
}
# $y = 2006
# $m = 10
# $d = 24

# 13  
Old 08-01-2006
sorry... i agree with you about learning up alil... but perl isn't really my thing.. it just happens.. that i need to modify this script to get it work...

i'm sorry for posting such questions... but thanks anyways for trying to help...
appreciate it..
# 14  
Old 08-01-2006
Quote:
Originally Posted by 12yearold
i'm sorry for posting such questions...
There's nothing wrong posting these questions. But what I would like to say is the fact, that if you do not have some prior learning on your side, you are unlikely to arrive at the answer on your own the next time and you will learn nothing, relying on others to give you the answers.

Therefore, help others help you.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem in calling a script inside a script

Hi team, I have a script in different folder. Now i want to call that script and execute that script from that path alone. My code is #!/bin/bash wname=yahoo PATH='/opt/IBM' wac=`/usr/bin/ls $PATH | /usr/bin/grep "$wname"` STOP=`/usr/bin/find $PATH/$wac -type f -name "stop.sh"`... (8 Replies)
Discussion started by: natraj005
8 Replies

2. Shell Programming and Scripting

Shell script newbie, what is problem with my script?

Hello, Ubuntu server 11.10 can anybody help what is problem with my shell script? #!/bin/bash #script to find out currently logged on user is root or not. if ] then echo "You are super" else echo "You are awesome!" fi When I run script, I get following output ./uid: line 3: I... (4 Replies)
Discussion started by: kaustubh
4 Replies

3. Shell Programming and Scripting

Problem while calling a script within a script

Hi , I have moduled my scripts in three scripts . From First script i am calling second and from second i am calling third for some check . Problem is with the third script call. ---In second script EXP ='test.\abc.\Server.*abc.xml.*' pid=$($HOME/bin/checkpid $EXP) --Third... (2 Replies)
Discussion started by: amrishn
2 Replies

4. Shell Programming and Scripting

Problem running a program/script in the background from a script

Hi all, I have a script that calls another program/script, xxx, to run in the background. Supposedly this program at most should finish within five (5) minutes so after five (5) minutes, I run some other steps to run the script into completion. My problem is sometimes the program takes... (5 Replies)
Discussion started by: newbie_01
5 Replies

5. Shell Programming and Scripting

Problem with a script

Hi everyone, I got a problem with a script. What it's supposed to do is: to take as arguments a directory name <dir> and a dimension (in byte) <dim>; if <dir> exists, to write name and dimension of every regular file within it that sizes lesser than <dim> in regFileList. Nothing happens... (10 Replies)
Discussion started by: Luke Bonham
10 Replies

6. UNIX for Dummies Questions & Answers

Problem with script

Hello All. I have a script that is suppossed to start up a daemon but when executed, simply hangs. Could you please take a look and let me know where the problem might be? TIA ################################################################### # # SCRIPT: dstart3000.sh # Bring up the Domain... (6 Replies)
Discussion started by: grin1dan
6 Replies

7. Shell Programming and Scripting

call shell script from perl cgi script problem

hi,, i have perl scipt with line : system('./try.sh $t $d $m'); in shell scipt try.sh i have the line: echo $1 its not printing value of $t that i hav passed..y is it so..i am running it from apache web server (2 Replies)
Discussion started by: raksha.s
2 Replies

8. Shell Programming and Scripting

ssh script problem problem

Hi Please help me with the following problem with my script. The following block of code is not repeating in the while loop and exiting after searching for first message. input_file ========== host001-01 host001-02 2008-07-23 13:02:04,651 ConnectionFactory - Setting session state... (2 Replies)
Discussion started by: pcjandyala
2 Replies

9. Shell Programming and Scripting

Help. Script problem

hey guys. i have a bunch of programs in a script that needs to run as root and the rest as another user, we'll call him gabriel. now, in this script, i want to run the first few lines as root. now, how do i, after running as root, tell the script to run the remaining lines as the user gabriel?... (3 Replies)
Discussion started by: Terrible
3 Replies

10. UNIX for Dummies Questions & Answers

Problem starting a script from a 'main'-script

Please Help! :o I have a main script (ksh) where another script is called (convert_picture). Normally this works ok, but since some changes has been made on the unix-server (I dont know what :( ) suddenly it doesnt work anymore: i get an error message: ksh: convert_picture not found. I am... (3 Replies)
Discussion started by: Rakker
3 Replies
Login or Register to Ask a Question