Some problem with script.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Some problem with script.
# 1  
Old 07-31-2006
Some problem with script.

guys i have a Script was not written by me... that delete a particular file once it ages 7 days...
never the less, the script is not working as planed...

can someone help me out?

@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; <-----WHY 1900??
$month = $2 - 1; <----- one month back???
$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;


ERROR received,

Use of uninitialized value in subtraction (-) at ./script line 81.
Use of uninitialized value in subtraction (-) at ./script line 82.
Month '-1' out of range 0..11 at ./script line 85


I don't understand some of the lines here... is there a software that would show you the output for each line? i think that would help tremendously!
# 2  
Old 07-31-2006
Message deleted, wrong input.

Last edited by tayyabq8; 07-31-2006 at 09:28 AM..
# 3  
Old 07-31-2006
Actually, the assignment syntax in the script is correct, this is perl.
# 4  
Old 07-31-2006
Oh sorry for that, I never noticed that and I dont any thing about PERL too.
# 5  
Old 07-31-2006
$logname doe not have a value. It appears to be a filename with an embedded date/time stamp.

UNIX time (internal) is a number of seconds since an arbitrary starting time.... 1900 is the 'earliest' year, so 2006 would be year 106 which is 2006 - 1900.

Months start counting from zero ie., Jan = zero , Feb = 1....
# 6  
Old 07-31-2006
Thanks jim... i believe the 1900 is the epoch year right?.. okay...
then something is wrong...
it seems that i earlier suspected that it could be the assignment of values, but reborg confirms that its correct... hmmmm...
# 7  
Old 08-01-2006
The epoch year is 1970.

Code:
$ perl -e "printf localtime(0) . \"\\n\";"
Wed Dec 31 18:00:00 1969

My time zone is GMT-6 hours, so I have to add 6 hours for the epoch:

Code:
$ perl -e "printf localtime(0 +(60)*(60)*(6) ) . \"\\n\";"
Thu Jan  1 00:00:00 1970

The error message indicates that variables $1 , $2 and $3 are not initialized.

What value is assigned to $logname?
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