LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-18-2006, 09:34 AM   #1
linx win
Member
 
Registered: Jan 2004
Posts: 390

Rep: Reputation: 31
Help with a bash script


I am trying to make a bash script to let the user to configure the proxy for the Konsole using the KDE proxy configarator gui to be able to use wget and apt-get. I did the following:
Code:
---------------- start -------------------------
#!/bin/bash
## 1st will open KDE proxy configarator
kcmshell proxy 
## 2nd will copy the settings to /etc/apt/apt.conf
CONF_DIR=~/.kde/share/config
ftp_Prox=`grep "^ftpProxy=" "${CONF_DIR}/kioslaverc" | sed -e 's/.*=\(.*\)/\1/'`
htp_Prox=`grep "^httpProxy=" "${CONF_DIR}/kioslaverc" | sed -e 's/.*=\(.*\)/\1/'`
htps_Prox=`grep "^httpsProxy=" "${CONF_DIR}/kioslaverc" | sed -e 's/.*=\(.*\)/\1/'`
 
 echo "APT::Cache-Limit 20000000;" > /etc/apt/apt.conf
 echo "Apt::Get::Purge;" >> /etc/apt/apt.conf
 echo "Acquire{" >> /etc/apt/apt.conf
 echo 'FTP::proxy' '"'$ftp_Prox'"'';' >> /etc/apt/apt.conf
 echo 'HTTP::proxy' '"'$htp_Prox'"'';' >> /etc/apt/apt.conf
 echo 'HTTPS::proxy' '"'$htps_Prox'"'';' >> /etc/apt/apt.conf
 echo "}" >> /etc/apt/apt.conf 
------------------- End ---------------------------
But the problem, the file I am trying to write the setting in (/etc/apt/apt.conf) requires root prevlige. Is there a way to aquire such prevlige using Xdialoge or kdialoge? I know how to do it from command line as follows:
Code:
if [ $(id -u) != 0 ]; then
	echo You have to be root to run this script.
	exec su -c "$0" || echo authorization failed. && exit 1
fi
but I do not want the user to see the command line.

Last edited by linx win; 01-18-2006 at 02:33 PM.
 
Old 01-18-2006, 09:51 AM   #2
scuzzman
Senior Member
 
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851

Rep: Reputation: 47
Your answer is sudo. For more information:
Code:
man sudo
That said, you really should enclose your code in [ code]...[ /code] markup. This way it's displayed a lot more legibly.
 
Old 01-18-2006, 02:30 PM   #3
linx win
Member
 
Registered: Jan 2004
Posts: 390

Original Poster
Rep: Reputation: 31
scuzzman

Thanks for reply. I am sorry for the miss up in the code. I revised it as you suggested.

Can you elaborate on how to use sudo in this case. My debian system does not allow normal users to do "sudo".

Another option is su command. Is there a way to pass a user name and password to su command? If there is I can use kdialog to ask the user to provide the root password and pass it on to the su command.

Last edited by linx win; 01-18-2006 at 02:38 PM.
 
Old 01-18-2006, 07:23 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Did you read the man page for sudo? The whole pt of the sudo tool is to allow (enable) named user(s) to do specified cmds above their normal privilege.
 
Old 01-19-2006, 12:26 AM   #5
linx win
Member
 
Registered: Jan 2004
Posts: 390

Original Poster
Rep: Reputation: 31
Yes, I read it but when I use sudo it just tells me: "knoppix is not in the sudoers file. This incident will be reported."
 
Old 01-19-2006, 08:21 AM   #6
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Rep: Reputation: 30
you need to edit the sudoers file.

if it is a freebsd or solaris distribution then it is /usr/local/etc/sudoers

openbsd /etc/sudoers (not sure of others)

always use the visudo to edit sudoers file.

sudoers file is of the following format.

Code:
user host=command


if you want to give permission to run all the commands on all the servers for a particular user
then

user ALL=ALL
 
Old 01-19-2006, 12:08 PM   #7
scuzzman
Senior Member
 
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851

Rep: Reputation: 47
As for your request for a solution involving 'su' you'd use:
Code:
su - root -c "command"
It will automatically prompt for the root password.
 
Old 01-19-2006, 04:10 PM   #8
linx win
Member
 
Registered: Jan 2004
Posts: 390

Original Poster
Rep: Reputation: 31
Thanks for help. I will try.
 
  


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
bash script help me. carboncopy Linux - Software 11 01-06-2005 01:38 AM
Bash Script cynicall Linux - Newbie 4 10-12-2004 09:19 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:01 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
Open Source Consulting | Domain Registration