LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Problems starting Impress with a script (https://www.linuxquestions.org/questions/linux-newbie-8/problems-starting-impress-with-a-script-448139/)

aabfm 05-24-2006 12:24 PM

Problems starting Impress with a script
 
:confused:
Does anyone know how to start an Impress presentation with a script and, as soon as Impress starts, continue with the script, i.e., leave Impress running and start another task.
So far my script is as follows:

#!/bin/bash
cd /home/xyz/docs
cp presentation.odp temp
cd temp
ooffice -invisible -show presentation.odp
cd ..
rename presentation.odp as p_old.odp

but it stops at the ooffice line instead of continue with the next line.
Thanks in advance.

MensaWater 05-24-2006 02:24 PM

Not familiar with Impress.

However what is happening is it is waiting for the following line to complete:
ooffice -invisible -show presentation.odp

before it will do the line:
cd ..

To prevent it waiting you need to make the earlier line ansynchronous. You do that by adding
an ampersand to the end of it:
ooffice -invisible -show presentation.odp &

That will prevent the cd .. from waiting for it. Since I'm not familiar with Impress I'm not
sure what impact doing your last line will have before the above line has completed.

aabfm 05-25-2006 03:57 AM

It worked in perfection!
With the ampersand at the end of the line it just finished the script and left Impress running.

Now I have another problem.
If I kill Impress from another script such as:

#!/bin/bash
pkill soffice

and start the first script once again

#!/bin/bash
cd /home/xyz/docs
cp presentation.odp temp
cd temp
ooffice -invisible -show presentation.odp &
cd ..
rename presentation.odp as p_old.odp

I can't put it to work again and this messages shows up:

/usr/lib/openoffice.org2.0/program/soffice.bin X11 error: Can't open display:
Set DISPLAY environment variable, use -display option
or check permissions of your X-server
(See "man X" resp. "man xhost" for details)

Thanks for your precious help!

aabfm 05-25-2006 05:32 AM

Adding to this, if I join both scripts into one like:

#!/bin/bash
pkill soffice
cd /home/xyz/docs
cp presentation.odp temp
cd temp
ooffice -invisible -show presentation.odp &
cd ..
rename presentation.odp as p_old.odp

saved it as scr_oo and programed crontab such as

20 11 * * * /home/xyz/scripts/scr_oo

to run it automatically at 11:20 it gives me the same error.
BUT if I start the script from the command line it works without any problem again and again and again.
Since I would like to schedule it to work is there any way to overcome this DISPLAY environment problem?

MensaWater 05-25-2006 09:03 AM

Commands issued from command line inherit the environment of the user that ran them. (In this case presumably that would be you.)

Commands run by cron have a minimal environment because they aren't executed by a real user. Therefore scripts run by cron need to include most of their environment.

Therefore in your script you need to set the DISPLAY variable. You should also setup PATH for the items you wish to use to be sure you get the right ones although it appears you may be finding them already.

While logged in as a user "echo $DISPLAY" will show you what the DISPLAY variable is set to. To set it manually you just add a line like:

export DISPLAY=X.X.X.X.:#.#

Where X.X.X.X is the IP of your display and #.# is the identifier where on the display you want it (usually can use 0.0 unless you have a desire for something else - can be just 0 instead of 0.0).


Example:

echo $DISPLAY
returns:
10.0.8.120:10.0

In script: export DISPLAY=10.0.8.120:10.0

aabfm 05-26-2006 02:45 AM

The %$&%"#"% message continues to appear.
When I tried the

echo $DISPLAY

it respond with

:0.0

which I used in the script as follows

#!/bin/bash
pkill soffice
cd /home/xyz/docs
cp presentation.odp temp
cd temp
export DISPLAY=:0.0
ooffice -invisible -display DISPLAY -show presentation.odp &
cd ..
rename presentation.odp as p_old.odp

aabfm 05-26-2006 02:56 AM

:)
Fantastic! Great!
Instead of

ooffice -invisible -display DISPLAY -show presentation.odp &

I used

ooffice -invisible -display :0.0 -show presentation.odp &

and it works in perfect perfection.

Just a question: does de export command forces de DISPLAY var to set as :0.0?
Thanks for your patience with this linux freshman.

MensaWater 06-06-2006 12:52 PM

Sorry was on vacation last week so didn't see your message until today.

When you set a shell variable in the Bourne/Korn shell variants you do:

VAR=value

Where "VAR" is the variable name and "value" is what you want the variable to contain. However when you set this it is only set in your immediate shell. Any subshells or other processes would not use it. The "export" tells it to set it globally so that subshells and other process WILL inherit it and use it.

The old syntax (in Bourne Shell) was:
VAR=value (declare the variable)
export VAR (export the variable)
(or VAR=value;export VAR - the semi-colon would have the same effect as typing it on two separate lines as it tells the first command to complete before doing the second one.)

With ksh and bash they simplified it by allowing you to do the export and declare in a single command:
export VAR=value

Of course VAR and value can be anything you want but there are some reserved variables (like DISPLAY, HOME, PATH) that you don't want to use for other purposes as they have special meaning.

So:
DISPLAY=:0.0 has "VAR" name of DISPLAY and "value" of :0.0 so it is this that "sets" your DISPLAY. The export as noted above makes it available to all subprocesses of the one that set the variable.

P.S. To see what a variable is set to you simply type "echo $VAR" where VAR is the name of the variable. Try doing:
echo $HOME
echo $DISPLAY
echo $PATH
to see what these variables are set to.

aabfm 06-25-2006 10:00 AM

Thanks for the info!
Precious knowledge for this newbie.


All times are GMT -5. The time now is 07:05 AM.