You are not logged in.

#1 2010-09-25 12:40:02

sweetthdevil
Member
Registered: 2009-10-20
Posts: 417

Shell Script - Need to Open terminal and Print output?

Hi All,

I have a script to update a git version of a software, but I would like to be able to check the output of the script in a terminal.

So in a nut shell, I want when launching the script:
- Terminal to Open
- All command to be executed in the terminal
- Terminal to close only if no error (do not know if it's possible?)

See below my very simple script:

Many thanks in advance for your time and advice,

rm -r /home/sweetth/banshee &&
cd /home/sweetth &&
git clone git://git.gnome.org/banshee &&
cd /home/sweetth/banshee &&
./autogen.sh &&
make

Offline

#2 2010-09-25 13:02:37

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Shell Script - Need to Open terminal and Print output?

'xterm -e <command>' opens xterm and executes <command>
I think $? returns zero if no errors.

Offline

#3 2010-09-25 13:29:37

jiehong
Member
Registered: 2009-03-19
Posts: 63
Website

Re: Shell Script - Need to Open terminal and Print output?

karol is right yo ucan use xterm.

To specify it that you want to run more than one command you can use the weak quotes: " "
Example :

 xterm -e "echo hello; echo This is the second command"

However the terminal will close as soon as your commands are finished. What you could do is to use a sleep at the end if your last command worked with a || like

make || sleep 50

which would run the sleep only if make fails.

You could also cat the output of your commands to only display the error (that means print nothing if no error).

Last edited by jiehong (2010-09-25 13:30:49)

Offline

#4 2010-09-25 13:39:24

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Shell Script - Need to Open terminal and Print output?

The question is, why do you need the terminal in the first place? You can execute the script and check the logs and make it do sth if it fails - send an a-mail etc.

The '-hold' option will keep the xterm window open, whether the command executed fails or not:

xterm -hold -e "echo hello; echo This is the second command"

Last edited by karol (2010-09-25 13:50:44)

Offline

#5 2010-09-25 14:06:23

xamaco
Member
From: Corsica, France
Registered: 2010-04-05
Posts: 87

Re: Shell Script - Need to Open terminal and Print output?

You could also use the script command.

Offline

#6 2010-09-25 14:08:28

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Shell Script - Need to Open terminal and Print output?

#!/bin/bash
echo ta-da
echo
if [ "$?" -eq 0 ]; then
     echo Good job!
else
     echo You failed!
fi
read -p "Press ENTER to close window."
echo

Run 'xterm -e <name_of_the_script>' and see if it's better than the '-hold' option.

Offline

#7 2010-09-25 15:58:37

sweetthdevil
Member
Registered: 2009-10-20
Posts: 417

Re: Shell Script - Need to Open terminal and Print output?

Many thanks for the reply,

I have now work on the script a lot more, it goes fetch some PKGBUILD from AUR to create some pkg (update quite regularly), but I am trying to make my script install/update those pkg via "gksudo pacman -U nameofpkg" but it return an error of wrong argument with gksudo "-U"

any idea?

Offline

#8 2010-09-25 16:19:21

skunktrader
Member
From: Brisbane, Australia
Registered: 2010-02-14
Posts: 1,580

Re: Shell Script - Need to Open terminal and Print output?

try using the -i argument to makepkg instead

Offline

#9 2010-09-25 16:21:10

sweetthdevil
Member
Registered: 2009-10-20
Posts: 417

Re: Shell Script - Need to Open terminal and Print output?

the issue is not to make those pkg but to install them, see command in script below:

cd ~/libpod &&
gksudo pacman -U gtk-sharp-beans-git** gio-sharp-git** gkeyfile-sharp-git** gudev-sharp-git** libgpod-sharp-git** 

Offline

#10 2010-09-25 16:33:19

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Shell Script - Need to Open terminal and Print output?

Have you tired any AUR helpers?

Offline

#11 2010-09-25 17:18:08

sweetthdevil
Member
Registered: 2009-10-20
Posts: 417

Re: Shell Script - Need to Open terminal and Print output?

I do not have an issue making those pkg, I want to install them via script

Offline

#12 2010-09-25 17:22:16

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Shell Script - Need to Open terminal and Print output?

sweetthdevil wrote:

I do not have an issue making those pkg, I want to install them via script

skunktrader wrote:

try using the -i argument to makepkg instead

sweetthdevil, what is wrong with this approach? Where does it fail?

Offline

#13 2010-09-25 17:30:05

sweetthdevil
Member
Registered: 2009-10-20
Posts: 417

Re: Shell Script - Need to Open terminal and Print output?

see output terminal while running those commands.

[sweetth@myhost ~]$ cd ~/libpod &&
> gksudo pacman -U gtk-sharp-beans-git** gio-sharp-git** gkeyfile-sharp-git** gudev-sharp-git** libgpod-sharp-git**
gksudo: invalid option -- 'U'
GKsu version 2.0.2

And this is where I have the issue,

Offline

#14 2010-09-25 17:38:39

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Shell Script - Need to Open terminal and Print output?

cd  /var/cache/pacman/pkg && sudo pacman -U xulrunner**

I have no problem running sudo.

Offline

#15 2010-09-25 17:43:44

sweetthdevil
Member
Registered: 2009-10-20
Posts: 417

Re: Shell Script - Need to Open terminal and Print output?

yes, but this in a script and need GKsudo to prompt for the password

Offline

#16 2010-09-25 17:49:41

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Shell Script - Need to Open terminal and Print output?

sweetthdevil wrote:

yes, but this in a script and need GKsudo to prompt for the password

I don't follow, if it's a script don't you want it non-interactive, just fire and forget? With the correct entries in sudoers file you won't be prompted for password.

Have a look at gksudo man page.

Offline

#17 2010-09-25 18:06:47

sweetthdevil
Member
Registered: 2009-10-20
Posts: 417

Re: Shell Script - Need to Open terminal and Print output?

Right,  I manage it differently
So I got my script to dl those PKGBUILD for those Ipod library needed for the latest Banshee, then dl the latest banshee git and "make" it.

for those who might be interested to keep their banshee-git update:

#!/bin/bash
xterm -hold -e "mkdir ~/libpod;
cd ~/libpod; 
mkdir ~/libpod/gtk-sharp-beans-git
cd ~/libpod/gtk-sharp-beans-git
wget http://aur.archlinux.org/packages/gtk-sharp-beans-git/gtk-sharp-beans-git/PKGBUILD;
wget http://aur.archlinux.org/packages/gtk-sharp-beans-git/gtk-sharp-beans-git/autogen_fix.patch;
makepkg -s;
mv gtk-sharp-beans-git** ~/libpod;
cd ~/libpod;
rm -rf ~/libpod/gtk-sharp-beans-git;
mkdir ~/libpod/gio-sharp-git;
cd ~/libpod/gio-sharp-git;
wget http://aur.archlinux.org/packages/gio-sharp-git/gio-sharp-git/PKGBUILD;
makepkg -s;
mv gio-sharp-git** ~/libpod;
cd ~/libpod;
rm -rf ~/libpod/gio-sharp-git;
mkdir ~/libpod/gkeyfile-sharp-git;
cd ~/libpod/gkeyfile-sharp-git;
wget http://aur.archlinux.org/packages/gkeyfile-sharp-git/gkeyfile-sharp-git/PKGBUILD;
makepkg -s;
mv gkeyfile-sharp-git** ~/libpod;
cd ~/libpod;
rm -rf ~/libpod/gkeyfile-sharp-git;
mkdir ~/libpod/gudev-sharp-git;
cd ~/libpod/gudev-sharp-git;
wget http://aur.archlinux.org/packages/gudev-sharp-git/gudev-sharp-git/PKGBUILD;
makepkg -s;
mv gudev-sharp-git** ~/libpod;
cd ~/libpod;
rm -rf ~/libpod/gudev-sharp-git;
mkdir ~/libpod/libpod-sharp-git;
cd ~/libpod/libpod-sharp-git;
wget http://aur.archlinux.org/packages/libgpod-sharp-git/libgpod-sharp-git/PKGBUILD;
makepkg -s;
mv libgpod-sharp-git** ~/libpod;
rm -rf ~/libpod/libpod-sharp-git;
cd ~/libpod;
sudo pacman -U gtk-sharp-beans-git** gio-sharp-git** gkeyfile-sharp-git** gudev-sharp-git** libgpod-sharp-git**;
rm -rf ~/banshee;
cd ~;
git clone git://git.gnome.org/banshee;
cd ~/banshee;
./autogen.sh;
make;
rm bin/Banshee.NotificationArea.dll*"

Offline

#18 2010-09-25 18:11:40

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Shell Script - Need to Open terminal and Print output?

Glad you got it working, but I still don't get you don't you use 'makepkg -si'.

Offline

#19 2010-09-25 18:28:40

sweetthdevil
Member
Registered: 2009-10-20
Posts: 417

Re: Shell Script - Need to Open terminal and Print output?

Well because I do not want to set up sudo to work without password, so like that I have the script asking me once for the password in xterm window

Offline

#20 2010-09-25 20:10:15

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Shell Script - Need to Open terminal and Print output?

sweetthdevil wrote:

Well because I do not want to set up sudo to work without password, so like that I have the script asking me once for the password in xterm window

I'm guessing you want to enter the password just once and not for every package, right? You can see if '--noconfirm' option for makepkg helps.

If you don't want to build in /tmp you can try this:

#!/bin/bash
# scriptname: bansheebuild

downloads="/home/karol/test_down"
apps="/home/karol/build_dir"
mkdir $downloads
mkdir $apps

for i in uzbl-git screen-git; do
#for i in banshee-git gtk-sharp-beans-git gio-sharp-git gkeyfile-sharp-git gudev-sharp-git libgpod-sharp-git; do
     cd $downloads
     wget http://aur.archlinux.org/packages/$i/$i.tar.gz
     bsdtar xf $i.tar.gz -C $apps && cd $apps/$i && makepkg -si --noconfirm PKGBUILD
done
rm -rf $downloads $apps

Adjust the folder paths and the packages you want to build and install. I've tested it on uzbl-git and screen-git.
Tarballs from AUR are downloaded to $downloads and extracted to $apps, where the sources are downloaded and built.
The last line removes both directories with all that was inside.

You can add the banshee part and run the whole script with

xterm -hold -e /path/to/bansheebuild

Why aren't you using http://aur.archlinux.org/packages.php?ID=26048 ?

Offline

Board footer

Powered by FluxBB