LinuxQuestions.org
Review your favorite Linux distribution.
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 11-23-2006, 09:01 AM   #16
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600

find ~/.mozilla/firefox -type f -maxdepth 2 -name prefs.js | while read f; <-- this line is needed because you cannot define the actual directory of prefs.js since it is actually saved in ~/mozilla/firefox/[RANDOM NAMe.Default]/pref.js
Right, we want to catch all profiles. My first idea was to parse the profiles.ini. This may be crude but faster.


so besides the way the file is found, it should be the same right? grep to find the line, and sed to substitute (arg1) with (arg2) in that said line?
Well in essence the grep is only there to see if there is a string occurrance. If it's not it would be futile (inefficient) to sed anyway.


Am i close
Yes, well done.


can anyone give me some guides to this bash script stuff besides that howto, coz I think this is where is the real LINUX power is, and I would like to learn how to use it constructively.

Code:
function help() { echo "Bash scripting guides:
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html 
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/index.html 
http://www.tldp.org/LDP/abs/html/"; }
 
Old 11-27-2006, 01:30 PM   #17
NDR008
Member
 
Registered: Nov 2006
Location: (Bristol or Coventry) (UK) or Malta
Distribution: openSUSE 11.0
Posts: 173

Original Poster
Rep: Reputation: 30
#!/bin/sh
# set -xe

case "$1" in
on) find ~/.mozilla/firefox -type f -maxdepth 2 -name prefs.js | while read f; do
grep -m1 -q "network.proxy.type.*.0)\;$" "${f}" && \
{ sed "s|network.proxy.type\", 0|network.proxy.type\", 2|g" \
"${f}" > "${f}.tmp" && mv -f "${f}.tmp" "${f}"; }


f="~/.kde/share/config/kioslaverc";
sed "s|ProxyType=0|ProxyType=2|g" "${f}" > "${f}" > "${f}.tmp" \
&& mv -f "${f}.tmp" "${f}";

done;;

off) #
find ~/.mozilla/firefox -type f -maxdepth 2 -name prefs.js | while read f; do
grep -m1 -q "network.proxy.type.*.2)\;$" "${f}" && \
{ sed "s|network.proxy.type\", 2|network.proxy.type\", 0|g" \
"${f}" > "${f}.tmp" && mv -f "${f}.tmp" "${f}"; }


f="~/.kde/share/config/kioslaverc";
sed "s|ProxyType=2|ProxyType=0|g" "${f}" > "${f}" > "${f}.tmp" \
&& mv -f "${f}.tmp" "${f}";

done;;

esac
exit 0

i wrote that, and get this error:
/home/ndr008/bin/proxy.sh: line 12: ~/.kde/share/config/kioslaverc: No such file or directory

BUT ~/.kde/share/config/kioslaverc exists....
 
Old 11-27-2006, 01:46 PM   #18
NDR008
Member
 
Registered: Nov 2006
Location: (Bristol or Coventry) (UK) or Malta
Distribution: openSUSE 11.0
Posts: 173

Original Poster
Rep: Reputation: 30
ok guys, i changed it to this:

#!/bin/sh
# set -xe

case "$1" in
on) find ~/.mozilla/firefox -type f -maxdepth 2 -name prefs.js | while read f; do
{ sed "s|network.proxy.type\", 0|network.proxy.type\", 2|g" \
"${f}" > "${f}.tmp" && mv -f "${f}.tmp" "${f}"; }

find ~/.kde/share/config/kioslaverc | while read f; do
{ sed "s|ProxyType=0|ProxyType=2|g" "${f}" > "${f}" > "${f}.tmp" \
&& mv -f "${f}.tmp" "${f}"; }

done;;


off) find ~/.mozilla/firefox -type f -maxdepth 2 -name prefs.js | while read f; do
{ sed "s|network.proxy.type\", 2|network.proxy.type\", 0|g" \
"${f}" > "${f}.tmp" && mv -f "${f}.tmp" "${f}"; }


find ~/.kde/share/config/kioslaverc | while read f; do
sed "s|ProxyType=2|ProxyType=0|g" "${f}" > "${f}" > "${f}.tmp" \
&& mv -f "${f}.tmp" "${f}";

done;;

esac
exit 0


and now get:

/home/ndr008/bin/proxy.sh: line 13: syntax error near unexpected token `;;'
/home/ndr008/bin/proxy.sh: line 13: `done;;'

 
Old 11-28-2006, 05:35 AM   #19
NDR008
Member
 
Registered: Nov 2006
Location: (Bristol or Coventry) (UK) or Malta
Distribution: openSUSE 11.0
Posts: 173

Original Poster
Rep: Reputation: 30
please anyone, could someone tell me how do i close the case statement?
 
Old 11-28-2006, 05:43 AM   #20
senyahnoj
Member
 
Registered: Jul 2004
Location: Gloucestershire, UK
Distribution: Ubuntu, Debian & Gentoo
Posts: 74

Rep: Reputation: 16
http://tldp.org/LDP/abs/html/testbranch.html

Last edited by senyahnoj; 11-28-2006 at 05:47 AM.
 
Old 11-28-2006, 06:23 AM   #21
NDR008
Member
 
Registered: Nov 2006
Location: (Bristol or Coventry) (UK) or Malta
Distribution: openSUSE 11.0
Posts: 173

Original Poster
Rep: Reputation: 30
thanks, now i understood that the 'done' wasn't part of the case statement and solved the problem

Give a man a fish and he will eat for a day, teach a man to fish and he will eat for life kind of thing
 
Old 11-28-2006, 06:29 AM   #22
NDR008
Member
 
Registered: Nov 2006
Location: (Bristol or Coventry) (UK) or Malta
Distribution: openSUSE 11.0
Posts: 173

Original Poster
Rep: Reputation: 30
for anyone who might want it:

#!/bin/sh
# set -xe

case "$1" in
on) find ~/.mozilla/firefox -type f -maxdepth 2 -name prefs.js | while read f; do
{ sed "s|network.proxy.type\", 0|network.proxy.type\", 2|g" \
"${f}" > "${f}.tmp" && mv -f "${f}.tmp" "${f}"; }
done

find ~/.kde/share/config/kioslaverc | while read f; do
{ sed "s|ProxyType=0|ProxyType=2|g" \
"${f}" > "${f}.tmp" && mv -f "${f}.tmp" "${f}"; }

done;;


off) find ~/.mozilla/firefox -type f -maxdepth 2 -name prefs.js | while read f; do
{ sed "s|network.proxy.type\", 2|network.proxy.type\", 0|g" \
"${f}" > "${f}.tmp" && mv -f "${f}.tmp" "${f}"; }

done

find ~/.kde/share/config/kioslaverc | while read f; do
{ sed "s|ProxyType=2|ProxyType=0|g" \
"${f}" > "${f}.tmp" && mv -f "${f}.tmp" "${f}"; }

done;;

esac
exit 0
 
Old 11-28-2006, 07:48 AM   #23
NDR008
Member
 
Registered: Nov 2006
Location: (Bristol or Coventry) (UK) or Malta
Distribution: openSUSE 11.0
Posts: 173

Original Poster
Rep: Reputation: 30
could someone help with this : http://www.linuxquestions.org/questi...76#post2521376 it is not a pure programming question, so i put it under software but its logic is derived from the script mentioned here.
 
  


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
Where can I edit my proxy IP address setting? Akhran Debian 2 10-15-2005 01:11 AM
Cannot Write/Edit files on hd.. Mmc245 Linux - Hardware 3 07-03-2005 06:08 PM
How can I edit IP settings? imsam Linux - Newbie 5 10-26-2004 01:18 PM
execute sript? cloids Linux - Software 1 01-15-2004 01:03 PM
Windows HD, can't write/edit as user hamsterdude Linux - General 14 07-07-2002 06:54 AM

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

All times are GMT -5. The time now is 04:50 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