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 |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
|
|
08-13-2012, 02:51 AM
|
#16
|
Member
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 649
Rep:
|
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?
|
|
|
08-13-2012, 07:01 AM
|
#17
|
Member
Registered: Dec 2002
Posts: 223
Original Poster
Rep:
|
Quote:
Originally Posted by 414N
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
- the script to execute has always the same name?
|
Yes. It will always have the same name
Quote:
Originally Posted by 414N
- 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.
|
|
|
08-13-2012, 08:29 AM
|
#18
|
Member
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 649
Rep:
|
Quote:
Originally Posted by riahc3
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
Yes. It will always have the same name
|
Good, another simplification going
Quote:
Originally Posted by riahc3
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.
|
|
|
08-14-2012, 02:03 AM
|
#19
|
Member
Registered: Dec 2002
Posts: 223
Original Poster
Rep:
|
Quote:
Originally Posted by 414N
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.
|
|
|
08-14-2012, 03:00 AM
|
#20
|
Member
Registered: Aug 2006
Posts: 609
Rep:
|
I am not fond of what you are trying to accomplish. For me this would be a general security issue.
|
|
|
08-14-2012, 03:00 AM
|
#21
|
Member
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 649
Rep:
|
Well, we could do something like this: - check if the new IP is already in place and, if so, do nothing;
- 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.
|
|
|
08-14-2012, 03:45 AM
|
#22
|
Member
Registered: Dec 2002
Posts: 223
Original Poster
Rep:
|
Quote:
Originally Posted by deadeyes
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
Well, we could do something like this: - check if the new IP is already in place and, if so, do nothing;
- 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
|
|
|
08-14-2012, 01:35 PM
|
#23
|
Member
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 649
Rep:
|
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
|
|
|
08-16-2012, 01:52 AM
|
#24
|
Member
Registered: Dec 2002
Posts: 223
Original Poster
Rep:
|
Quote:
Originally Posted by 414N
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...
|
|
|
08-16-2012, 03:09 AM
|
#25
|
Member
Registered: Dec 2002
Posts: 223
Original Poster
Rep:
|
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.
Last edited by riahc3; 08-16-2012 at 03:10 AM.
|
|
|
08-16-2012, 03:56 AM
|
#26
|
Member
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 649
Rep:
|
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?
|
|
|
08-16-2012, 03:58 AM
|
#27
|
Member
Registered: Dec 2002
Posts: 223
Original Poster
Rep:
|
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
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
|
|
|
08-16-2012, 05:00 AM
|
#28
|
Member
Registered: Dec 2002
Posts: 223
Original Poster
Rep:
|
If you need me to explain what exactly the second script needs to do, please ask Thank you.
|
|
|
08-16-2012, 05:04 AM
|
#29
|
Member
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 649
Rep:
|
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.
|
|
|
08-17-2012, 02:24 AM
|
#30
|
Member
Registered: Dec 2002
Posts: 223
Original Poster
Rep:
|
Quote:
Originally Posted by 414N
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.
|
|
|
All times are GMT -5. The time now is 05:27 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|