LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-13-2012, 02:51 AM   #16
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 649

Rep: Reputation: 190Reputation: 190

I guess there should be no issues with inotify on ARM. See man inotify for additional info.
If you prefer a shell based solution, I guess we need additional information, like:
  • is the USB device always mounted in the same locations?
  • the script to execute has always the same name?
  • is there a way to look if the script needs to be run?
 
Old 08-13-2012, 07:01 AM   #17
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by 414N View Post
I guess there should be no issues with inotify on ARM. See man inotify for additional info.
If you prefer a shell based solution, I guess we need additional information, like:
  • is the USB device always mounted in the same locations?
  • Yes. It will always be /tmp/media/sda1 or if it gets confudes because it still thinks it is mounted, /tmp/media/sda2. Either way I can check all I want problably
    Quote:
    Originally Posted by 414N View Post
  • the script to execute has always the same name?
  • Yes. It will always have the same name
    Quote:
    Originally Posted by 414N View Post
  • is there a way to look if the script needs to be run?
If it is on the USB and I plug it in, it has to run. As a matter of fact, once I plug it in, it runs and it can demount if you wish. This way, I unplug it and then replug it, it mounts again and it runs again if neccesary.
 
Old 08-13-2012, 08:29 AM   #18
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 649

Rep: Reputation: 190Reputation: 190
Quote:
Originally Posted by riahc3 View Post
Yes. It will always be /tmp/media/sda1 or if it gets confudes because it still thinks it is mounted, /tmp/media/sda2. Either way I can check all I want problably
Good. I think that with a proper grep on /etc/mtab this matter can be solved in 0 seconds
Quote:
Originally Posted by riahc3 View Post
Yes. It will always have the same name
Good, another simplification going
Quote:
Originally Posted by riahc3 View Post
If it is on the USB and I plug it in, it has to run. As a matter of fact, once I plug it in, it runs and it can demount if you wish. This way, I unplug it and then replug it, it mounts again and it runs again if neccesary.
Okay, but I wanted to know another thing (I probably chose the worst words to ask it). With this autorun script you're going to overwrite some IP settings inside a config file for OpenVPN, if I'm not mistaken. Shouldn't you make sure, prior to running the script, that it really needs to overwrite those settings? Think of a user continuously plugging in and out the USB drive with the script (not the smartest of users, I presume ): every time the drive is plugged in the script is run and the relevant config line is overwritten over and over.
To sum it all up: are you really sure it is desirable for clients to run the script everytime the drive is inserted without checking if it's needed (assuming this can be checked) or without being prompted about the change that's gonna happen (something like "old IP: xx.xx.xx.xx ->new IP: yy.yy.yy.yy. Apply? [Y/n]")?

Last edited by 414N; 08-13-2012 at 08:31 AM.
 
Old 08-14-2012, 02:03 AM   #19
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by 414N View Post
Okay, but I wanted to know another thing (I probably chose the worst words to ask it). With this autorun script you're going to overwrite some IP settings inside a config file for OpenVPN, if I'm not mistaken. Shouldn't you make sure, prior to running the script, that it really needs to overwrite those settings? Think of a user continuously plugging in and out the USB drive with the script (not the smartest of users, I presume ): every time the drive is plugged in the script is run and the relevant config line is overwritten over and over.
To sum it all up: are you really sure it is desirable for clients to run the script everytime the drive is inserted without checking if it's needed (assuming this can be checked) or without being prompted about the change that's gonna happen (something like "old IP: xx.xx.xx.xx ->new IP: yy.yy.yy.yy. Apply? [Y/n]")?
I thought about this and Ive come up with several solutions:

1: Selfdelete the script from the USB once it has ran
2: Unmount the USB once the script has ran
3: Both

I cant prompt the user as there is no GUI. Im inclinded to do 1 as this would avoid the user running it over and over and over again (like you mentioned). He would either have to redownload it from his email or I would have to resend it to him.
 
Old 08-14-2012, 03:00 AM   #20
deadeyes
Member
 
Registered: Aug 2006
Posts: 609

Rep: Reputation: 79
I am not fond of what you are trying to accomplish. For me this would be a general security issue.
 
Old 08-14-2012, 03:00 AM   #21
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 649

Rep: Reputation: 190Reputation: 190
Well, we could do something like this:
  1. check if the new IP is already in place and, if so, do nothing;
  2. log every action performed by the script in a relevant log file, i.e. /var/log/scriptName.log
This introduces a new problem, though: in the long run, the log file could become huge if, for example, the "smartest user ever" from my previous example has nothing to do apart from playing with a USB drive and the router.
This could be mitigated if you're already using logrotate for the other log files on the machine.
 
Old 08-14-2012, 03:45 AM   #22
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by deadeyes View Post
I am not fond of what you are trying to accomplish. For me this would be a general security issue.
Why? Noone knows what the script is named nor do they have access to the actual shell. Also, this is for a pastry company; If they have shell script programmers, they are doing it wrong....



Quote:
Originally Posted by 414N View Post
Well, we could do something like this:
  1. check if the new IP is already in place and, if so, do nothing;
  2. log every action performed by the script in a relevant log file, i.e. /var/log/scriptName.log
This introduces a new problem, though: in the long run, the log file could become huge if, for example, the "smartest user ever" from my previous example has nothing to do apart from playing with a USB drive and the router.
This could be mitigated if you're already using logrotate for the other log files on the machine.
Logging? Why would I log? Im not too intrested in logging.

We could do that check also. I dont mind if it overwrites it but yes, checking is more efficient so I agree.

BTW, on record, I have NO idea on how to write these scripts so........I hope you can help me write this. Thank you very much
 
Old 08-14-2012, 01:35 PM   #23
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 649

Rep: Reputation: 190Reputation: 190
Let's start writing down the cron-able script (this should work on ash):
Code:
#!/bin/sh

scriptName="XYZ.sh"
usbRoot=/tmp/media
scriptLoc="$(find "$usbRoot"/sd* -name "$scriptName" | head -n1 )"

if [ "$scriptLoc" ]
then
	sh "$scriptLoc"
fi
You can try it using a dumbed-down XYZ.sh script which prints a line to a file, like this:
Code:
#!/bin/sh

echo "$(date) - cron script launched successfully!" >> /tmp/testWrite.txt
Of course the USB drive needs to be mounted in /tmp/media/sdXn on the test machine, unless you change the usbRoot variable
 
Old 08-16-2012, 01:52 AM   #24
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by 414N View Post
Let's start writing down the cron-able script (this should work on ash):
Code:
#!/bin/sh

scriptName="XYZ.sh"
usbRoot=/tmp/media
scriptLoc="$(find "$usbRoot"/sd* -name "$scriptName" | head -n1 )"

if [ "$scriptLoc" ]
then
	sh "$scriptLoc"
fi
You can try it using a dumbed-down XYZ.sh script which prints a line to a file, like this:
Code:
#!/bin/sh

echo "$(date) - cron script launched successfully!" >> /tmp/testWrite.txt
Of course the USB drive needs to be mounted in /tmp/media/sdXn on the test machine, unless you change the usbRoot variable
Looks great! Im going to try this right now. Will tell you results now...
 
Old 08-16-2012, 03:09 AM   #25
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
Didnt work

Here is a screenshot, showing what I believe is all the neccesary information to diagnostic this:

http://img52.imageshack.us/img52/6609/crontab.png

And yes, I waited over a minute.
Attached Thumbnails
Click image for larger version

Name:	crontab.png
Views:	63
Size:	62.0 KB
ID:	10383  

Last edited by riahc3; 08-16-2012 at 03:10 AM.
 
Old 08-16-2012, 03:56 AM   #26
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 649

Rep: Reputation: 190Reputation: 190
Strange, I just re-tested it on my machine and it works ok.
Are you sure your cron daemon is running? How did you edit the crontab for root?
 
Old 08-16-2012, 03:58 AM   #27
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
Restarted the device and now it works!

Thats step one: Making a script that works so thats great. Thank you

Now, the next thing is implement what I actually want to do.

---------- Post added 08-16-12 at 08:59 AM ----------

Quote:
Originally Posted by 414N View Post
Strange, I just re-tested it on my machine and it works ok.
Are you sure your cron daemon is running? How did you edit the crontab for root?

After restarting the device, it now works
 
Old 08-16-2012, 05:00 AM   #28
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
If you need me to explain what exactly the second script needs to do, please ask Thank you.
 
Old 08-16-2012, 05:04 AM   #29
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 649

Rep: Reputation: 190Reputation: 190
Some additional details are indeed needed.
What file contains the OpenVPN settings you need to change?
Post an example reporting the exact line to be changed and how it should be changed.
 
Old 08-17-2012, 02:24 AM   #30
riahc3
Member
 
Registered: Dec 2002
Posts: 223

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by 414N View Post
Some additional details are indeed needed.
What file contains the OpenVPN settings you need to change?
Post an example reporting the exact line to be changed and how it should be changed.
client
proto udp
remote 192.168.100.199 1194
cipher AES-128-CBC
user root
group root
verb 2
mute 20
keepalive 10 120
comp-lzo
persist-key
persist-tun
float
resolv-retry infinite
nobind
ca /etc/ssl/certs/openvpn-tunnel0-ca.crt
cert /etc/ssl/certs/openvpn-tunnel0.crt
key /etc/ssl/certs/openvpn-tunnel0.key
dh /etc/ssl/certs/dh1024.pem
dev tun
up "/etc/openvpn/tunnel0-up"
down "/etc/openvpn/tunnel0-down"

Thats the configuration file. Where it says:

remote 192.168.100.199 1194

is what I need to replace. I need to read off a usb that contains a file named (for example) update.txt that has:

remote 192.168.100.123 1194

and replace it.
 
  


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
make a USB drive bootable cccc Linux - General 2 10-25-2008 11:23 PM
How do you make a usb drive bootable? comcastuser Linux - General 4 06-25-2007 02:19 AM
execute shell script when USB drive plugged in OneSeventeen Linux - Hardware 2 10-28-2005 10:27 AM
creating shell script that executes as root regardless of who runs the script? m3kgt Linux - General 13 06-04-2004 10:23 PM
can you make a usb drive bootable? citrus Linux - Newbie 4 05-16-2004 04:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:27 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