ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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:
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
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
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;
}
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.