LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 07-13-2011, 10:32 AM   #1
mrm5102
Member
 
Registered: Apr 2011
Location: Philadelphia
Posts: 165

Rep: Reputation: 3
Expect and Shell Scripts Not Executing Correctly???


Hello All,

PC OS Specs:
OpenSuSE 11.4 - 2.6.37.6-0.5-desktop --> Gnome

So I wrote these 3 simple scripts to do a job that is kind of annoying to do everytime I need it, so I am trying to automate it somewhat.

The script is made up of 3 files:
1. Shell Script - calls 2 expect files
2. Expect Script - executes mount cmd
3. Expect Script - executes umount cmd

The script works just fine if I run it in terminal (but that is kind of pointless bc it would be the same as having to open a terminal and executing the cmds directly).

So what I am trying to do is, I added a "Custom Application Launcher" to the taskbar that simply executes what ever file you specify, but when I click that icon it only displays the "xmessage" cmd and does not execute anything else...

Here are my scripts:
callMount.sh
Code:
#!/bin/sh

#DISPLAY=":0.0"
mount | grep -i sdb
GREP_RETCODE=$?
#echo "Grep-ReturnCode = "$GREP_RETCODE

if (("$GREP_RETCODE" == "0"))
then
	./umount.exp
	xmessage -center "SSD has been UNMOUNTED"
else
	./mount.exp
	xmessage -center "SSD has been MOUNTED"
fi
mount.exp
Code:
#!/usr/bin/expect -f

set force_conservative 0  ;# set to 1 to force conservative mode even if
			  ;# script wasn't run conservatively originally
if {$force_conservative} {
	#set send_slow {1 .1}
	proc send {ignore arg} {
		sleep .1
		exp_send -s -- $arg
	}
}

set timeout 1

#spawn /bin/sudo mount /dev/sdb1 /mnt/SSD
spawn $env(SHELL)

expect_after {
	timeout {
	   exit 2
	}
}

expect {
	timeout {exit 2}
	"userName*" {send "sudo mount /dev/sdb1 /mnt/SSD\r"}
}
expect {
	timeout {exit 2}
	"*password:" {send "myPassword\r"}
}
expect {
	timeout {exit 0}
#	"userName*" {send "exit\r"}
}
umount.exp
Code:
#!/usr/bin/expect -f

set force_conservative 0  ;# set to 1 to force conservative mode even if
			  ;# script wasn't run conservatively originally
if {$force_conservative} {
	#set send_slow {1 .1}
	proc send {ignore arg} {
		sleep .1
		exp_send -s -- $arg
	}
}

set timeout 1

#spawn /bin/sudo mount /dev/sdb1 /mnt/SSD
spawn $env(SHELL)

expect_after {
	timeout {
	   exit 2
	}
}

expect {
	timeout {exit 2}
	"userName*" {send "sudo umount /mnt/SSD\r"}
}
expect {
	timeout {exit 2}
	"*password:" {send "myPassword\r"}
}
expect {
	timeout {exit 0}
}

So I know each command works on their own, because I have run each one from the command-line but when I click the icon for the "Custom Application Launcher" the only thing that happens is that it displays the "xmessage" cmd.

Any help would be greatly appreciated...

Thanks,
Matt
 
Old 07-13-2011, 10:56 AM   #2
mrm5102
Member
 
Registered: Apr 2011
Location: Philadelphia
Posts: 165

Original Poster
Rep: Reputation: 3
Sorry but I found the answer... Don't worry about answering this thread.

It wasn't working because I didn't have the FULL path to the expect scripts in the cmd.

I just had to change the lines in the shell script that say:
./mount.exp change to /home/MountSSD/mount.exp
./umount.exp change to /home/MountSSD/umount.exp



Thanks and sorry for the uneeded post,
Matt
 
  


Reply



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
procmail is not executing scripts correctly ChrisInAlpharetta Linux - Server 6 04-22-2011 01:44 PM
stop konqueror executing shell scripts ahh Linux - Software 2 03-27-2005 06:00 AM
Prevent konqueror from executing shell scripts Dave Farrance Mandriva 1 05-30-2004 08:37 PM
Executing Shell Scripts? l0f33t Linux - General 7 08-17-2003 03:36 PM
Executing shell scripts justinv Linux - General 6 01-26-2003 07:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 04:59 AM.

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