LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-08-2005, 05:10 AM   #1
steve007
Member
 
Registered: Jun 2005
Distribution: Fedora Core 3
Posts: 96

Rep: Reputation: 15
Perl Script Error


Hello people,
I was wondering if someone can help me out with an error im getting when i run a perl script. I am not a perl programmer, in fact i know nothing about the language, i was working off someone elses code but it hasnt worked. the error i get on here when i run it is as follows:
syntax error near unexpected token '('

this error occurs on line two, if i take out line two and run it, it still produces the error on the next line, but it has a problem with cat etc/xtab

I;m using Fedora Core, new to all this and very stuck. here's the code below

Code:
#!/usr/bin/perl -w

my $exit = system("touch /disks/Disk-1/.testmount");
unless($exit == 0){
    system("cat /etc/xtab | grep -v /disks/Disk-1 > /etc/xtab");
    system("cat /etc/xtab | grep -v /disks/Disk-2 > /etc/xtab");    
    system("service nfs restart");

    system("mount -t -p mypass smbfs 192.168.1.15:/Disk-1 /disks/Disk-1");
    system("mount -t -p mypass smbfs 192.168.1.15:/Disk-2 /disks/Disk-2");

}
 
Old 09-08-2005, 05:38 AM   #2
cardy
Member
 
Registered: Jan 2005
Location: Shropshire, England, UK
Distribution: RedHat, Fedora, CentOS..........
Posts: 121

Rep: Reputation: 19
I can't see anything wrong with that and cutting and pasting that code onto my machine it runs fine.
Is that the exact code your running ?
 
Old 09-08-2005, 05:46 AM   #3
steve007
Member
 
Registered: Jun 2005
Distribution: Fedora Core 3
Posts: 96

Original Poster
Rep: Reputation: 15
yes its the exact code im running

why on earth does it come up with that error? what does that error mean anyways?
 
Old 09-08-2005, 05:53 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: NetBSD, Void, Debian, Mint, Ubuntu, Puppy, Raspbian
Posts: 3,487

Rep: Reputation: 233Reputation: 233Reputation: 233
did you copy WIndows-> unix?

maybe you have dozy microsoft CR/LF in there?

cat -vets
 
Old 09-08-2005, 06:31 AM   #5
steve007
Member
 
Registered: Jun 2005
Distribution: Fedora Core 3
Posts: 96

Original Poster
Rep: Reputation: 15
I manually typed the code into lynix into the Gedit text editor, it seems to make parts of the code colours as if it has registered that the code is correct, like parts are dark red, pink, green and black.
is there any setting i need to do at all? someone said to chmod +x the file for it to be executeable, i dont know how to do this, but i went to the properties of the file and checked the execute box on permissions tab. this is the command i use to run the script in a terminal... perhaps im doing it wrong:

sh /root/checkmount
 
Old 09-08-2005, 06:49 AM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Ubuntu/WSL
Posts: 9,782

Rep: Reputation: 481Reputation: 481Reputation: 481Reputation: 481Reputation: 481
Quote:
sh /root/checkmount
Interpreting perl code with a shell interpreter is not the best way to have it running properly ...
try:
Code:
chmod +x /root/checkmount
/root/checkmount
 
Old 09-08-2005, 07:04 AM   #7
steve007
Member
 
Registered: Jun 2005
Distribution: Fedora Core 3
Posts: 96

Original Poster
Rep: Reputation: 15
ah ha, getting somewhere now.... still have an error but its different and on a different line... due to compilation error? here is the error i get

syntax error at /root/checkmount line 5, near ") system"
execution of /root/.checkmount aborted due to compilation errors.

i just did ur last bit of commands there, the chmod and /root/checkmount to get that error
 
Old 09-08-2005, 07:10 AM   #8
steve007
Member
 
Registered: Jun 2005
Distribution: Fedora Core 3
Posts: 96

Original Poster
Rep: Reputation: 15
oh no, my mistake it does run
but it doesnt do the job its supposed to do... it doesnt mount anything
 
Old 09-08-2005, 10:05 AM   #9
steve007
Member
 
Registered: Jun 2005
Distribution: Fedora Core 3
Posts: 96

Original Poster
Rep: Reputation: 15
How do i get it to mount the volume, accepting a password in the line (the password is to the network share) and /etc/xtab file doesnt exist, what is it? whats it for? my system is Fedora Core 3 by the way
 
Old 09-08-2005, 11:00 AM   #10
steve007
Member
 
Registered: Jun 2005
Distribution: Fedora Core 3
Posts: 96

Original Poster
Rep: Reputation: 15
Hello, I have found the error, but im still having some trouble with it.
this is the corrected code:

Code:
#!/usr/bin/perl -w

my $exit = system("touch /disks/Disk-1/.testmount");
unless($exit == 0){
    system("cat /etc/xtab | grep -v /disks/Disk-1 > /etc/xtab");
    system("cat /etc/xtab | grep -v /disks/Disk-2 > /etc/xtab");    
    system("service nfs restart");

    system("mount -t smbfs -o password=mypass 192.168.1.15:/Disk-1 /disks/Disk-1");
    system("mount -t smbfs -o password=mypass 192.168.1.15:/Disk-2 /disks/Disk-2");

}
now, if i take it all out except the top entry and the line for actually mounting it, it tries to mount it but gives me a long list of stuff with options in it etc, it says that this command is designed to be run in /bin/mount so i try it and edit the line to show /bin/mount -t smbfs ......... but it still doesnt work, what the hell is wrong with this thing?
also that top part, touch /disks/Disk-1/testmount, (oh by the way i probably failed to mention im trying to check if a network share is still available with this script by the way, ooops) if the network share isnt available, wouldnt it just make the testmount file in /disks/Disk-1 anyway since the folder exists locally? if i try and touch 192.168.1.15//Disk-1 it doesnt work, even if its mounted or not, but the machine with the share on is turned on.

sorry i never explained what i was trying to do initially, but i will explain it now.
what im trying to do is make a script that will detect if a network share is available (incase the machine hosting the files is turned off) if its not detected, then do nothing, if it is detected then try and mount the share back onto the system.
the folder exists in this location 192.168.1.15/Disk-1
and 192.168.1.15/Disk-2

on the fedora system there are these folders made
/disks/Disk-1
/disks/Disk-2

i was then going to make this script run every so often in a cron job.... any ideas how i can get this script working would be a blessing, thank you
 
Old 09-09-2005, 06:19 AM   #11
cardy
Member
 
Registered: Jan 2005
Location: Shropshire, England, UK
Distribution: RedHat, Fedora, CentOS..........
Posts: 121

Rep: Reputation: 19
This is an alternative way of doing what you are trying.

First whilst the disk is mounted create a file on the disk partition called .testmount

Code:
echo 1 > /disks/Disk-1/.testmount
The program below can then be used to see if the partition is mounted, it tries to open that file for read (the user who you run the script as MUST have permissions to read the .testmount file, I have assumed your running this as root) If the file can be opened it just closes the file handle that is created, if not it executes the commands you have specified to remount the partition.

Code:
#!/usr/bin/perl

# Try to open the precreated file .testmount

$return = open TEST_FH, " < /disks/Disk-1/.testmount";

if (!defined $return) {
	# The file could not be opened, try to remount the drive

#	print "Unable to open file : $!\n";

	system("cat /etc/xtab | grep -v /disks/Disk-1 > /etc/xtab");
	system("cat /etc/xtab | grep -v /disks/Disk-2 > /etc/xtab");    
	system("service nfs restart");
	system("mount -t smbfs -o password=mypass 192.168.1.15:/Disk-1 /disks/Disk-1");
	system("mount -t smbfs -o password=mypass 192.168.1.15:/Disk-2 /disks/Disk-2");
} else {
	# The File opened, close the file handle and quit.
	
#	print "File opened\n";
	close TEST_FH;
}
 
Old 09-12-2005, 04:12 AM   #12
steve007
Member
 
Registered: Jun 2005
Distribution: Fedora Core 3
Posts: 96

Original Poster
Rep: Reputation: 15
Hello,
Thanks for the script it looked allot more promising than what i had before. however it didnt do the job of mounting the disk back - have i got something wrong with the commands in there?
i dont have a file called xtab in /etc i found one in /var/lib/nfs when i searched for it and it has 0 bytes, so not sure if there is anything in there. i cant open it anywayso i changed the path to /var/lib/nfs/xtab and it still hasnt mounted anything. when i type at the terminal /root/checkmount it just goes onto the next line in the terminal waiting for me to type another command... as if its executed it but when i check it, it hasnt mounted it. is something wrong with the mount command im using? something is not right with it and i dont know what.

im really stuck on this and its so annoying, thanks for your help tho.

Steve
 
Old 09-13-2005, 02:52 AM   #13
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,814

Rep: Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553
I'd start by typing in those shell cmds one at a time directly at the cmd line and check what each one does/returns.
Also, using the system() fn means running a sub-shell, which means any env settings made disappear when the sub-shell exits.
 
Old 09-13-2005, 04:21 AM   #14
steve007
Member
 
Registered: Jun 2005
Distribution: Fedora Core 3
Posts: 96

Original Poster
Rep: Reputation: 15
I run the cat command ages ago, i know the mounting part works, the cat command doesnt seem to do anything, i type
cat /etc/xtab | grep -v /disks/Disk-1 > /etc/xtab
into the terminal and it does nothing, the file doesnt even exist, but if it does (if i actually put it there) it seems to wipe any data that was in there and make it empty. this isnt my command or code, i dont know any perl script and i dont know many commands, i dont even know what that one is supposed to do but was given it by an "expert". Cardy did well with giving me the code ive been using, it looked more likely to work than the other one. but i think something is wrong with the actual command in there.

Steve
 
Old 09-13-2005, 04:32 AM   #15
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: NetBSD, Void, Debian, Mint, Ubuntu, Puppy, Raspbian
Posts: 3,487

Rep: Reputation: 233Reputation: 233Reputation: 233
Code:
cat /etc/xtab | grep -v /disks/Disk-1 > /etc/xtab
you can't do this!

you are simultaneously reading and writing /etc/xtab.
you will just end up with a truncated file.
you need to do an intermediate file:

Code:
cat /etc/xtab | grep -v /disks/Disk-1 > newxtab
you should be very careful messing about in /etc
you could end up regretting it

Last edited by bigearsbilly; 09-13-2005 at 04:35 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Burning a .dmg file Perl Script giving zlib error zwyrbla Linux - General 1 08-19-2005 05:02 PM
cgi-bin error regarding perl script hamish Linux - Software 11 12-09-2004 11:16 AM
Converting a Windows Perl script to a Linux Perl script. rubbercash Programming 2 07-19-2004 11:22 AM
how to find the pid of a perl script from shell script toovato Linux - General 1 12-19-2003 07:25 PM
Including methods from a perl script into another perl script gene_gEnie Programming 3 01-31-2002 06:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration