LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-20-2004, 07:52 PM   #1
Braveheart1980
Member
 
Registered: Jan 2004
Location: Greece!
Distribution: Ubuntu 9.10
Posts: 633
Blog Entries: 1

Rep: Reputation: 30
Help a newbie write a script!


I wanna some help to write a script(my first one!).Here is what i wanna do
I have a Georce 6800 (ROCKZZZZZZZZZZZ!!) and i have created 2 xorg.conf files under /etc/X11 : one named xorg.conf.monitor with only my monitor enabled (Tv disabled) and an xorg.conf.dualview with tv out enabled.I wanna write a script which asks me whether i want tv enabled or not and it will then overwrite the xorg.conf file with the apropriate one (xorg.conf.monitor or xorg.conf.dualview) . After selecting dualview or monitor , X should restart so changes will take effect.Of course all this should be done as root so the script should ask for root's password at the beging.I think it'll look like this

su # (give root's password )
What do u want (a) DualView {Monitor+TV} or (b) Monitor only
if answer = a then cp xorg.conf.dualview xorg.conf
if answer = b then cp xorg.conf.monitor xorg.conf
restart x server

Any help?????
 
Old 09-20-2004, 09:05 PM   #2
serz
Member
 
Registered: Apr 2003
Location: Buenos Aires, Argentina
Distribution: Slackware, Gentoo
Posts: 397

Rep: Reputation: 30
Code:
#!/bin/bash

echo -n "What do you want (a) DualView {Monitor+TV) or (b) Monitor only: "

read option

case $option in
        a) su -c "cd /etc/X11 ; cp xorg.conf.dualview xorg.conf"
        ;;
        b) su -c "cd /etc/X11 ; cp xorg.conf.monitor xorg.conf"
        *) echo "Incorrect option."
        ;;
esac
As for how to restart the server.. I don't know what you could use.
 
Old 09-21-2004, 05:54 AM   #3
Braveheart1980
Member
 
Registered: Jan 2004
Location: Greece!
Distribution: Ubuntu 9.10
Posts: 633
Blog Entries: 1

Original Poster
Rep: Reputation: 30
Thanx a lot serz!!

Anyone have any idea how to restart the X server?
 
Old 09-21-2004, 07:28 AM   #4
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 63
What distribution? In Mandrake:
service dm restart

Yves.
 
Old 09-21-2004, 07:51 AM   #5
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE 42.1_64+Tumbleweed-KDE, Mint 17.3+18.3
Posts: 4,101

Rep: Reputation: Disabled
Mhm, I woudn't copy, just create a symbolic link as /etc/X11/Xorg.conf which then points to one of your config-files...
 
Old 09-21-2004, 01:51 PM   #6
Braveheart1980
Member
 
Registered: Jan 2004
Location: Greece!
Distribution: Ubuntu 9.10
Posts: 633
Blog Entries: 1

Original Poster
Rep: Reputation: 30
I use fedora core 2.service dm restart didn't work!

PS Thank for the linking idea!
 
Old 09-21-2004, 02:54 PM   #7
ky-lab_rat
Member
 
Registered: Jan 2004
Posts: 44

Rep: Reputation: 15
to restart the xserver service
shell ways

init 3
init 5

or

telinit 3
telinit 5

GUI ways

finding the "restart X server"
button on your kdm/gdm login screen
or
by pressing Ctrl-Alt-Bkspace,

Last edited by ky-lab_rat; 09-21-2004 at 03:14 PM.
 
Old 09-21-2004, 06:08 PM   #8
Braveheart1980
Member
 
Registered: Jan 2004
Location: Greece!
Distribution: Ubuntu 9.10
Posts: 633
Blog Entries: 1

Original Poster
Rep: Reputation: 30
Hmmm.Not what i am looking 4.Anyone else?
 
Old 09-22-2004, 02:53 AM   #9
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 63
It really depends at what point you want to restart X. This will always work for example:
killall X (or is it XFree?)
startx
But it is really usable only when no user is logged-in. Actually, whatever method you choose to restart X, this should be true, because anyway you do it, logged-in users will loose their session.

Yves.
 
Old 09-22-2004, 03:36 AM   #10
inimino
Member
 
Registered: Sep 2004
Location: Colorado, US
Distribution: Gentoo, Debian
Posts: 32

Rep: Reputation: 15
Best is to use your display manager (xdm, gdm, or kdm) unless you are using startx.
 
Old 09-22-2004, 05:02 AM   #11
Braveheart1980
Member
 
Registered: Jan 2004
Location: Greece!
Distribution: Ubuntu 9.10
Posts: 633
Blog Entries: 1

Original Poster
Rep: Reputation: 30
Then maybe what command should i use to log off ?
 
Old 09-22-2004, 05:33 AM   #12
powadha
Member
 
Registered: Nov 2003
Location: Utrecht
Distribution: Debian SID
Posts: 651

Rep: Reputation: 31
Just an idea for your script: Can't you build in a check to see whatever .conf file you are using? Like if you answer dual and your last use was dual it doesn't copy and won't restart just use the settings already there. Could save you some useless restarts of X.....Like the script though, could use something like it....
 
Old 09-22-2004, 06:10 AM   #13
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
You cannot stop and restart X in a script called from X.

That is, say your script has a line like so:
Code:
# kill and restart X
kill `pidof X` && startx
This will not work because once X is killed, all of it's child processes are killed, including the xterm/aterm/konsole/whatever you ran the script from. 'startx' never gets run. You can use your script to set an Xorg.conf file and kill X, but you will need to startx manually.

That being said, if you use ctrl+alt+Fn to get a new console and run the script from there it will work with this line:
Code:
kill `pidof X` && sleep 5 && startx
The 'sleep 5' makes it wait 5 seconds before starting X or you will get an 'X server already started' error, as it takes a few seconds to shut it down...

And btw, change those lines to:
Code:
COMMAND="cd /etc/X11; if [ -e xorg.conf ]; then \
rm xorg.conf; fi; ln -s xorg.conf.dualview xorg.conf"
su -c ${COMMAND}
Really no point in the extra disk write...plus you need to erase the link if it already exists.

Last edited by bulliver; 09-22-2004 at 06:28 AM.
 
Old 09-22-2004, 07:04 AM   #14
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
Ok after all that, this is what I would do:
Code:
#!/bin/bash

echo -n "What do you want (a) DualView {Monitor+TV) or (b) Monitor only: "
read option

[ -e /etc/X11/xorg.conf ] && [ -h /etc/X11/xorg.conf ] && rm /etc/X11/xorg.conf \
    || echo "xorg.conf is not a link. exiting"; exit 1

case $option in
        a) su -c "cd /etc/X11; ln -s xorg.conf.dualview xorg.conf"
        ;;
        b) su -c "cd /etc/X11; ln -s xorg.conf.monitor xorg.conf"
        *) echo "Incorrect option."; exit 1
        ;;
esac

killx () {
        sleep 3
        kill `pidof X`
}

restartx () {
        sleep 5
        startx
}

if [ $TERM = "xterm" ]; then
        echo "You need to restart X manually"
        echo "ctrl-c for abort"
        killx
fi

echo "Killing and restarting X"
echo "ctrl-c for abort"
killx
restartx

exit 0

Last edited by bulliver; 09-22-2004 at 07:14 AM.
 
Old 09-22-2004, 07:40 AM   #15
inimino
Member
 
Registered: Sep 2004
Location: Colorado, US
Distribution: Gentoo, Debian
Posts: 32

Rep: Reputation: 15
Quote:
Originally posted by bulliver
You cannot stop and restart X in a script called from X.

That is, say your script has a line like so:
Code:
# kill and restart X
kill `pidof X` && startx
Did the OP say he was using startx?
Most people use GDM, XDM, KDM.
If you fall into this category you can just kill X and your display manager will restart it for you.

You will have to log in again, however.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How to write init script shahrokhnikou Programming 4 10-24-2005 04:08 PM
How to write a Script Blake Linux - Software 6 07-18-2004 12:41 PM
how to write this script? MeganageM Linux - Newbie 1 03-10-2004 06:01 PM
Help with a script I need to write... cmfarley19 Programming 9 12-06-2003 01:10 PM
Im trying to write a script or prog (newbie needs help desperatly!) bripage Programming 19 08-10-2002 10:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:57 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration