This forum has been archived. All content is frozen. Please use KDE Discuss instead.

scripts in Autostart do not work [SOLVED]

Tags: None
(comma "," separated)
mrambo
Registered Member
Posts
5
Karma
0
Hello,

I'm trying to use scripts in .kde4/Autostart (and shutdown) to mount cifs shares to local user mount points. The scripts work as intended from konsole but do not when placed in Autostart. I have added logging to try to see what is failing but cannot find anything. Everything in the script seems to work except the one or two lines which do the work.

Here is a code snippet after adding the variables for returning results.

Code: Select all
SUDORESULT=`echo "$SUDOPWD" | /usr/bin/sudo -v -S`
echo "Running as user $USER with home $HOME - sudoresult: $SUDORESULT" > /tmp/info.txt
~
HMNT=`sudo mount -t cifs //$SERV/$USER $HOME/$CHKMNT -o uid=$USER,gid=$USER,credentials=$HOME/.credentials`
echo "mounting $SERV/$USER to $HOME/$CHKMNT with result: $HMNT" >> /tmp/info.txt


The logging returns...
Code: Select all
Running as user mrambo with home /home/mrambo - sudoresult:
Found the credentials and kdm-mounts files
mounting blackgate/mrambo to /home/mrambo/mnt/homedir with result:


The results are null which they should be if no error is returned. But the share is not mounted. In way of background... the scripts I am using are descended from some I used a number of years ago with a LTSP lab in the public school I work for. LTSP at that time used gnome/gdm and these scripts were used in the PreSession/PostSession gdm processes and worked without difficulty though I must add that at the time they used smbmount/smbumount instead of mount.cifs. The latter requires all the sudo nonsense as non-root users are prevented from mounting their own network resources to their own local mountpoints. I could of course put a link on the desktop that the user clicks but the result of that is that they usually forget to click the unlink when they are done. The kio slaves are not usable as they do not expose the shares in any way that non-kde software/processes can use that I can find.

Any ideas why this does not work?

Mike

Last edited by mrambo on Thu Jan 03, 2013 3:29 pm, edited 1 time in total.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Assuming you are placing script files in ~/.kde4/Autostart, please make sure they are executable, have an appropriate shebang (such as #!/bin/bash) and have the *.sh file extension. I suspect you may be using bashisms, which the default interpreter (likely /bin/sh which under Ubuntu is dash) is falling over on.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
mrambo
Registered Member
Posts
5
Karma
0
The bash shebang is there (not /bin/sh). Forgot to mention - this in with kde 4.8.5 and Mageia 2. Sorry about that oversight. The execution and name are also right.

Code: Select all
[mrambo@mhr-d351 ~]$ ll ~/.kde4/Autostart/
total 3
-rwxr-x--- 1 mrambo mrambo 2594 Jan  1 10:15 kdm-mount.sh*


When I added logging statements to the script I did get data in the log file so the script itself has to be running. In fact, it appears that everything except the mount statements are working as they should. In testing I logged various data to ensure the script was processing and variables working as I intended. It all looks good except that there are no mounted shares when it is finished. If I run this exact script in konsole I end up with the shares mounted as they should be (just tested it again).

It looks like only the sudo mount... lines do not work for some reason. I'm not even seeing anything in the system logs indicating sudo ran when the script runs via Autostart - something I do see when ran from konsole. It looks like the sudo statement alone doesn't run. Since I don't know how kde processes this stuff I don't know whether there is something that prevents these statements from working in this context.

Thanks.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Just to verify that the arguments are indeed inserted properly, have you tried simply echoing the mount command into a file?


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
mrambo
Registered Member
Posts
5
Karma
0
Yes. If echoed the command with arguments is output as expected. But I may have just figured out an important part of what is happening though still not why.

I changed the logging on the 'sudo mount' lines to redirect stdout and stderr to my log file and found nothing was logged. Next I changed the whole long mount command line to just 'mount' with the redirection to my log. My log then included all my mount points as expected. Next I stuck sudo in front of mount (sudo mount) and nothing was logged. Made me think having sudo there broke it as if sudo was blocked. But finally I made the line read 'ssudo mount' and redirected that which should have shown an error in the log and found nothing. It looks like when the command string includes a space the line does not run.

In interest of clarity...

Code: Select all
sudo mount -t cifs //$SERV/$USER $HOME/$CHKMNT -o uid=$USER,gid=$USER,credentials=$HOME/.credentials 2>&1 >> /tmp/info.txt


Nothing is logged.

Code: Select all
mount 2>&1 >> /tmp/info.txt


My mount points are logged.

Code: Select all
sudo mount 2>&1 >> /tmp/info.txt


Nothing is logged.

Code: Select all
ssudo mount 2>&1 >> /tmp/info.txt


Nothing is logged - not even the error which should have been generated.

Thoughts?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: scripts in Autostart do not work

Wed Jan 02, 2013 11:14 pm
Extremely odd. Do you see anything of particular relevance (maybe try some echo commands) in ~/.xsession-errors which may indicate why those commands are failing?

I have a script which disables the Nepomuk filewatcher as follows, and it runs fine:
Code: Select all
sleep 2s && qdbus org.kde.NepomukServer /servicemanager stopService nepomukfilewatch &


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
mrambo
Registered Member
Posts
5
Karma
0
Ok. I've figured it out - or at least am on the path to a work around. KDE is not the source of the problem. First, I had made a mistake in the stderr redirection and thus was not seeing the error being thrown by either the intentional typo I had inserted and more importantly the one from sudo. The real problem is sudo. On my distro I have to comment out requiretty with visudo in order to script sudo as I was trying to do. Once that was done I was able to find a way to get sudo to start working although I still have to fine tune my script to successfully do what I'm trying to do. It appears the things that work when running the script in a terminal are not the same as those that are needed when running the script by other means.

In any case, KDE isn't really the problem (even though I could wish for better ways to mount/utilize network resources while using KDE).
Thanks for the help. :)


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft