[expert] bash script: interesting case
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Dear all, I have a dial-up server (it dials the ISP to provide internet connection for a small LAN) on a remote location. Now, I want to ssh to that server. Can I make somekind of script so that everytime it dials the ISP, it will send it's assigned IP to my email? All this time, everytime I want to ssh it, I call the local admin for the IP address. Errr... one more thing, it doesn't have qmail installed or neither sendmail or any other mailserver package. Can bash'es mail command handle it? Thanks. - -- Fajar http://linux.arinet.org Linux mdk91.sistek.kom 2.4.21-0.13mdk GNU/Linux 14:49:48 up 7:14, 10 users, load average: 0.25, 0.43, 0.25 Quote of the day: Win98 is called Win98 because 98% of all hardware components will NEVER have WDM-drivers -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE/sJXWMai9kCFqACoRAibuAJ0esiex0mnbEoBk13lxbB64R57y+gCfUB1V xbOyJyR/6tsUFzgLkKe6mdA= =PYHL -END PGP SIGNATURE- Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash script: interesting case
Fajar Priyanto wrote: Dear all, I have a dial-up server (it dials the ISP to provide internet connection for a small LAN) on a remote location. Now, I want to ssh to that server. Can I make somekind of script so that everytime it dials the ISP, it will send it's assigned IP to my email? All this time, everytime I want to ssh it, I call the local admin for the IP address. Well, you can ask the admin to set a on-connection script to just be like: #!/bin/bash echo $YOUR_IP_ADDR | mail [EMAIL PROTECTED] BTW, I have a dial-up connection too - I use KPPP that always shows my current IP address. Errr... one more thing, it doesn't have qmail installed or neither sendmail or any other mailserver package. Can bash'es mail command handle it? mail command usually needs /usr/sbin/sendmail to work. On my 9.2 machine I have /usr/sbin/sendmail soft-linked to /etc/alternatives/mta so it makes postfix handle things as I guess. Artemio. Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash script: interesting case
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Tuesday 11 November 2003 03:31 pm, Artemio wrote: #!/bin/bash echo $YOUR_IP_ADDR | mail [EMAIL PROTECTED] mail command usually needs /usr/sbin/sendmail to work. On my 9.2 machine I have /usr/sbin/sendmail soft-linked to /etc/alternatives/mta so it makes postfix handle things as I guess. Artemio. Thanks Artemio, If I haven't installed any mailserver on it, can I use mail command to utilize the ISP's smtp instead? - -- Fajar http://linux.arinet.org Linux mdk91.sistek.kom 2.4.21-0.13mdk GNU/Linux 15:48:38 up 8:13, 10 users, load average: 0.27, 0.56, 0.52 Quote of the day: Windows 99 has been released! (PC Magazine, April 2013) -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE/sKKwMai9kCFqACoRAhgNAJ9lGGxc2vpgqzZ11faCfwOZIAIm9ACfZvWg Y1mQlmku1RBK72KWTNocttw= =HUvP -END PGP SIGNATURE- Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash script: interesting case
On September 1993 plus 3723 days Fajar Priyanto wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Dear all, I have a dial-up server (it dials the ISP to provide internet connection for a small LAN) on a remote location. Now, I want to ssh to that server. Can I make somekind of script so that everytime it dials the ISP, it will send it's assigned IP to my email? All this time, everytime I want to ssh it, I call the local admin for the IP address. Uhm...there's way easier ways to do this, like http://dtdns.com/ Don't suffer, just use a working method :) Vox -- Think of the Linux community as a niche economy isolated by its beliefs. Kind of like the Amish, except that our religion requires us to use _higher_ technology than everyone else. -- Donald B. Marti Jr. pgp0.pgp Description: PGP signature
Re: [expert] bash script: interesting case
Fajar Priyanto wrote: If I haven't installed any mailserver on it, can I use mail command to utilize the ISP's smtp instead? Hmm... not sure... the way it works is something like as follows: local mail command - your local mail daemon - isp mail daemon or isp mail command - isp mail daemon - your local mail daemon - your local mail Also, you want your isp to mail you your IP address, right? There are two ways: 1. your isp mails it to your machine directly. both your machine and isp's need to have a mail server running 2. your isp mails it to your mailbox in www. isp needs a mail server running and you need a pop3/imap client to get your mail. I have postfix running in my dial-up machine and I can send mail to anyone with it. Artemio. Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash script: interesting case
On Tue, 2003-11-11 at 07:55, Fajar Priyanto wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Dear all, I have a dial-up server (it dials the ISP to provide internet connection for a small LAN) on a remote location. Now, I want to ssh to that server. Can I make somekind of script so that everytime it dials the ISP, it will send it's assigned IP to my email? All this time, everytime I want to ssh it, I call the local admin for the IP address. What about using dynamic DNS? There are tons of places that do this for free. Personally I use no-ip.com Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash scripting question - simple regular expression?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Jim C wrote on Tue, Jan 14, 2003 at 07:28:07PM -0800 : newldif=./file2 Herein lies part of the problem. I don't want to use a file for scaleability reasons and I can't think of any reason why it should be nescesary. In theory I should be able to store all of the text in a shell variable and then redirect the output of echo to ldapadd. So far I can get the text in but when I pass it to You're right, this is part of the problem. Shell variables don't keep the newline characters. Witness: [todd@fiji ~/tmp]$ cat file1 #!/bin/bash TEMP=line1 line2 line3 echo $TEMP [todd@fiji ~/tmp]$ ./file1 line1 line2 line3 I don't see why you just don't do this: #!/bin/bash if [ ! $1 ]; then echo Sorry, you must pass the userid to add to directory. exit 1 fi binddn=cn=root,dc=microverse,dc=net pw4binddn=[deleted for security] ldaphost=ldap://localhost; base=ou=Computers,dc=microverse,dc=net basetest=ou=People,dc=microverse,dc=net minimumUID=501 groupnum=421 # 1. Search the LDAP database and return all uidNumber attributes in a # given base store=`ldapsearch -LLL -D $binddn -H $ldaphost -b$base -x (cn=*) uidNumber | \ grep uidNumber | \ sed -e 's/^uidNumber://' | sort -nr | head -n 1` newtest=`ldapsearch -LLL -D $binddn -H $ldaphost -b$basetest -x (cn=*) uidNumber | \ grep uidNumber | \ sed -e 's/^uidNumber://' | sort -nr` echo ${newtest[0]} #It is best not to start at 0 or 1 as these could be privledged. if [ $store = ] then store=$minimumUID else store=`expr $store + 1` fi LDAPADD=ldapadd -vx -D $binddn -W $pw4binddn $LDAPADD hrdoc dn: uid=$1,ou=Computers,dc=microverse,dc=net objectClass: top objectClass: account objectClass: posixAccount uidNumber: $store uid: $1 cn: $1 gidNumber: $groupnum homeDirectory: /dev/null loginShell: /bin/false gecos: Machine Account description: Machine Account hrdoc echo `expr $store + 1` Blue skies... Todd - -- Todd Lyons -- MandrakeSoft, Inc. http://www.mandrakesoft.com/ Favourite shell: bash, though I also like 'init=/usr/bin/emacs' --Andrew Tridgell Cooker Version mandrake-release-9.1-0.1mdk Kernel 2.4.20-2mdk -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE+JZ2clp7v05cW2woRAg2MAJwPtm26YsK8sFRccdmRYkHuFECsCACgynvb 43Dip0+6exTBJitKBjZHjP4= =/76n -END PGP SIGNATURE- Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash scripting question - simple regular expression?
I finally got around to giving your suggestion a try. :-) cat $newldif hrdoc dn: uid=$1,ou=Computers,dc=microverse,dc=net objectClass: top objectClass: account objectClass: posixAccount uidNumber: $store uid: $1 cn: $1 gidNumber: $groupnum homeDirectory: /dev/null loginShell: /bin/false gecos: Machine Account description: Machine Account hrdoc echo $newldif This produces: [root@enigma scripts]# ./adduser adlfalj ./adduser: line 42: $newldif: ambiguous redirect $newldif hrdoc dn: uid=$1,ou=Computers,dc=microverse,dc=net objectClass: top objectClass: account objectClass: posixAccount uidNumber: $store uid: $1 cn: $1 gidNumber: $groupnum homeDirectory: /dev/null loginShell: /bin/false gecos: Machine Account description: Machine Account hrdoc cat $newldif This causes the script to halt at some point and gives no output if you replace the 'cat' with 'echo'. Todd Lyons wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Jim C wrote on Mon, Jan 13, 2003 at 10:16:41AM -0800 : What I am trying to do is create a sort of virtual file. I've already tried using the here document and it doesn't seem to be working for me. What I am trying to do exactly is create an LDIF file for passing to an LDAP database. I have each line stored in an individual shell variable like so: There are two ways to do this: 1) Create an ldif file, then call ldap* with that ldif file. 2) Just pass it all to ldap* on stdin. The syntax I've been trying looks like this: ldapadd -x -D $binddn -w placepasswordhere hrdoc line1=dn: uid=$1,ou=Computers,dc=microverse,dc=net; line2=objectClass: top snip Look at this: #!/bin/bash cat $1.ldif hrdoc dn: uid=$1,ou=Computers,dc=microverse,dc=net objectClass: top objectClass: account objectClass: posixAccount uidNumber: $store uid: $1 cn: $1 gidNumber: $groupnum homeDirectory: /dev/null loginShell: /bin/false gecos: Machine Account description: Machine Account hrdoc Then you just do 'ldapadd -x -f $1.ldif blah blah blah' In all cases the here document doesn't seem to make it to the ldapadd command which I know reads from standard-in. All you gotta do is change the command portion of the above that I quoted: #!/bin/bash ldapadd -x blah blah blah hrdoc dn: uid=$1,ou=Computers,dc=microverse,dc=net objectClass: top objectClass: account objectClass: posixAccount uidNumber: $store uid: $1 cn: $1 gidNumber: $groupnum homeDirectory: /dev/null loginShell: /bin/false gecos: Machine Account description: Machine Account hrdoc Blue skies... Todd - -- MandrakeSoft USA http://www.mandrakesoft.com Mandrake: An amalgam of good ideas from RedHat, Debian, and MandrakeSoft. All in all, IMHO, an unbeatable combination. --Levi Ramsey on Cooker ML Cooker Version mandrake-release-9.1-0.1mdk Kernel 2.4.20-2mdk -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE+Iy/Ylp7v05cW2woRAhwMAJoDELaI+O82WNuz5SRnujaXG5y7hQCfUdlY dCj3ZneaqniZkaaADmAFVD4= =O07o -END PGP SIGNATURE- Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash scripting question - simple regular expression?
Grrr!! What gets me is why this doesn't work: echo -e $output ldapadd -x -D $binddn -W $pw4binddn where echo -e produces: [root@enigma scripts]# ./adduser alkjdfal dn: uid=alkjdfal,ou=Computers,dc=microverse,dc=net objectClass: top objectClass: account objectClass: posixAccount uidNumber: 501 uid: alkjdfal cn: alkjdfal gidNumber: 421 homeDirectory: /dev/null loginShell: /bin/false gecos: Machine Account description: Machine Account 502 --different echo statement If I do echo -e $output test.ldif and then ldapadd -x -D cn=root,dc=microverse,dc=net -f test.ldif from the command line it works fine! Do you think this is a bug in ldapadd? Todd Lyons wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Jim C wrote on Mon, Jan 13, 2003 at 10:16:41AM -0800 : What I am trying to do is create a sort of virtual file. I've already tried using the here document and it doesn't seem to be working for me. What I am trying to do exactly is create an LDIF file for passing to an LDAP database. I have each line stored in an individual shell variable like so: There are two ways to do this: 1) Create an ldif file, then call ldap* with that ldif file. 2) Just pass it all to ldap* on stdin. The syntax I've been trying looks like this: ldapadd -x -D $binddn -w placepasswordhere hrdoc line1=dn: uid=$1,ou=Computers,dc=microverse,dc=net; line2=objectClass: top snip Look at this: #!/bin/bash cat $1.ldif hrdoc dn: uid=$1,ou=Computers,dc=microverse,dc=net objectClass: top objectClass: account objectClass: posixAccount uidNumber: $store uid: $1 cn: $1 gidNumber: $groupnum homeDirectory: /dev/null loginShell: /bin/false gecos: Machine Account description: Machine Account hrdoc Then you just do 'ldapadd -x -f $1.ldif blah blah blah' In all cases the here document doesn't seem to make it to the ldapadd command which I know reads from standard-in. All you gotta do is change the command portion of the above that I quoted: #!/bin/bash ldapadd -x blah blah blah hrdoc dn: uid=$1,ou=Computers,dc=microverse,dc=net objectClass: top objectClass: account objectClass: posixAccount uidNumber: $store uid: $1 cn: $1 gidNumber: $groupnum homeDirectory: /dev/null loginShell: /bin/false gecos: Machine Account description: Machine Account hrdoc Blue skies... Todd - -- MandrakeSoft USA http://www.mandrakesoft.com Mandrake: An amalgam of good ideas from RedHat, Debian, and MandrakeSoft. All in all, IMHO, an unbeatable combination. --Levi Ramsey on Cooker ML Cooker Version mandrake-release-9.1-0.1mdk Kernel 2.4.20-2mdk -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE+Iy/Ylp7v05cW2woRAhwMAJoDELaI+O82WNuz5SRnujaXG5y7hQCfUdlY dCj3ZneaqniZkaaADmAFVD4= =O07o -END PGP SIGNATURE- Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash scripting question - simple regular expression?
On Tue, 14 Jan 2003 12:58:30 -0800 Jim C [EMAIL PROTECTED] wrote: Grrr!! What gets me is why this doesn't work: echo -e $output ldapadd -x -D $binddn -W $pw4binddn where echo -e produces: [root@enigma scripts]# ./adduser alkjdfal dn: uid=alkjdfal,ou=Computers,dc=microverse,dc=net objectClass: top objectClass: account objectClass: posixAccount uidNumber: 501 uid: alkjdfal cn: alkjdfal gidNumber: 421 homeDirectory: /dev/null loginShell: /bin/false gecos: Machine Account description: Machine Account 502 --different echo statement If I do echo -e $output test.ldif and then ldapadd -x -D cn=root,dc=microverse,dc=net -f test.ldif from the command line it works fine! Do you think this is a bug in ldapadd? here is what says man: The entry information is read from standard input or from file through the use of the -f option. so why not to try this: echo -e $output | ldapadd -x -D cn=root,dc=microverse,dc=net bye jipe Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash scripting question - simple regular expression?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Jim C wrote on Tue, Jan 14, 2003 at 11:31:20AM -0800 : I finally got around to giving your suggestion a try. :-) cat $newldif hrdoc dn: uid=$1,ou=Computers,dc=microverse,dc=net objectClass: top objectClass: account objectClass: posixAccount uidNumber: $store uid: $1 cn: $1 gidNumber: $groupnum homeDirectory: /dev/null loginShell: /bin/false gecos: Machine Account description: Machine Account hrdoc echo $newldif This produces: [root@enigma scripts]# ./adduser adlfalj ./adduser: line 42: $newldif: ambiguous redirect You've got something else going on cause it works on mine. (Are you sure that you're using the bash shell?) [todd@fiji ~/tmp]$ cat file1 #!/bin/bash # newldif=./file2 # cat $newldif hrdoc dn: uid=$1,ou=Computers,dc=microverse,dc=net objectClass: top objectClass: account objectClass: posixAccount uidNumber: $store uid: $1 cn: $1 gidNumber: $groupnum homeDirectory: /dev/null loginShell: /bin/false gecos: Machine Account description: Machine Account hrdoc # cat $newldif [todd@fiji ~/tmp]$ ./file1 todd dn: uid=todd,ou=Computers,dc=microverse,dc=net objectClass: top objectClass: account objectClass: posixAccount uidNumber: uid: todd cn: todd gidNumber: homeDirectory: /dev/null loginShell: /bin/false gecos: Machine Account description: Machine Account This causes the script to halt at some point and gives no output if you replace the 'cat' with 'echo'. Sounds like 1) You've got a misplaced backtick. 2) You're using different delimiters for the hrdoc start point and hrdoc endpoint. Post the WHOLE script so we can see what you're doing. If you change anything make sure you say exactly what you change. All you gotta do is change the command portion of the above that I quoted: #!/bin/bash ldapadd -x blah blah blah hrdoc dn: uid=$1,ou=Computers,dc=microverse,dc=net objectClass: top objectClass: account objectClass: posixAccount uidNumber: $store uid: $1 cn: $1 gidNumber: $groupnum homeDirectory: /dev/null loginShell: /bin/false gecos: Machine Account description: Machine Account hrdoc What I said originally should still work. Blue skies... Todd - -- MandrakeSoft USA http://www.mandrakesoft.com cat /boot/vmlinuz /dev/dsp #for great justice Cooker Version mandrake-release-9.1-0.1mdk Kernel 2.4.20-2mdk -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE+JLl8lp7v05cW2woRAuSQAKDOd7bKbEgO3kt6eL8SLrZHLcwwHACcCSWk r7X2YShaye9fOJwX7rcsyWQ= =559n -END PGP SIGNATURE- Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash scripting question - simple regular expression?
jipe wrote: here is what says man: The entry information is read from standard input or from file through the use of the -f option. so why not to try this: echo -e $output | ldapadd -x -D cn=root,dc=microverse,dc=net This produces an error, i.e. I get the usage text for ldapadd if I try it. Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash scripting question - simple regular expression?
echo $newldif This produces: [root@enigma scripts]# ./adduser adlfalj ./adduser: line 42: $newldif: ambiguous redirect You've got something else going on cause it works on mine. (Are you sure that you're using the bash shell?) [root@enigma scripts]# echo $SHELL /bin/bash [root@enigma scripts]# [todd@fiji ~/tmp]$ cat file1 #!/bin/bash # newldif=./file2 Herein lies part of the problem. I don't want to use a file for scaleability reasons and I can't think of any reason why it should be nescesary. In theory I should be able to store all of the text in a shell variable and then redirect the output of echo to ldapadd. So far I can get the text in but when I pass it to ldapadd it executes, returns no error messages but the new record does not show up on the ldap server. Since it works from the command line using an ldif file it logically cannot be an issue of access to the server. Also, no encryption is currently enabled. Now # cat $newldif hrdoc ... description: Machine Account ... Post the WHOLE script so we can see what you're doing. If you change anything make sure you say exactly what you change. It's a mess so remember, you asked for it. ;-) I've been doing all kinds of tests to try and figure a way around the problem. The algorithm works like this: 1. Get a list of uidNumbers 2. Sort them. 3. Take the one off the top (the largest) 4. Add one to it. 5. Create the text of a new record using the new uidNumber. #!/bin/bash binddn=cn=root,dc=microverse,dc=net pw4binddn=[deleted for security] ldaphost=ldap://localhost; base=ou=Computers,dc=microverse,dc=net basetest=ou=People,dc=microverse,dc=net minimumUID=501 groupnum=421 #complete=`echo $line1 $line2 $line3 $line4 $line5 $line6 $line7 $line8 $line9 $line10 $line11 $line12` #ldapsearch -LL -v -D cn=proxyuser,dc=microverse,dc=net -H ldap://localhost -bdc=microverse,dc=net -x (cn=proxyuser) #1. Search the LDAP database and return all uidNumber attributes in a given base store=`ldapsearch -LLL -D $binddn -H $ldaphost -b$base -x (cn=*) uidNumber | \ grep uidNumber | \ sed -e 's/^uidNumber: //' | sort -nr | head -n 1` newtest=`ldapsearch -LLL -D $binddn -H $ldaphost -b$basetest -x (cn=*) uidNumber | \ grep uidNumber | \ sed -e 's/^uidNumber: //' | sort -nr` echo ${newtest[0]} #It is best not to start at 0 or 1 as these could be privledged. if [ $store = ] then store=$minimumUID else store=`expr $store + 1` fi #ldapadd -x -D $binddn -w $pw4binddn line1=dn: uid=$1,ou=Computers,dc=microverse,dc=net\n; line2=objectClass: top\n line3=objectClass: account\n line4=objectClass: posixAccount\n line5=uidNumber: $store\n line6=uid: $1\n line7=cn: $1\n line8=gidNumber: $groupnum\n line9=homeDirectory: /dev/null\n line10=loginShell: /bin/false\n line11=gecos: Machine Account\n line12=description: Machine Account\n output=$line1$line2$line3$line4$line5$line6$line7$line8$line9$line10$line11$line12 echo -e $output | ldapadd -vx -D $binddn -W $pw4binddn echo -e $output ldapadd -vx -D $binddn -W $pw4binddn echo -e $output echo -e $output test.ldif #cat $output #echo $output #$output hrdoc #dn: uid=$1,ou=Computers,dc=microverse,dc=net #objectClass: top #objectClass: account #objectClass: posixAccount #uidNumber: $store #uid: $1 #cn: $1 #gidNumber: $groupnum #homeDirectory: /dev/null #loginShell: /bin/false #gecos: Machine Account #description: Machine Account #hrdoc #cat $line1 $line2 $line3 $line4 $line5 $line6 $line7 $line8 $line9 $line10 $line11 $line12 ldapadd -x -D $binddn -w $pw4binddn #complt=$line1$line2$line3$line4$line5$line6$line7$line8$line9$line10$line11$line12 #echo `expr $store + 1` Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash scripting question - simple regular expression?
Herein lies part of the problem. I don't want to use a file for scaleability reasons and I can't think of any reason why it should be nescesary. In theory I should be able to store all of the text in a shell variable and then redirect the output of echo to ldapadd. So far I can get the text in but when I pass it to ldapadd it executes, returns no error messages but the new record does not show up on the ldap server. Since it works from the command line using an ldif file it logically cannot be an issue of access to the server. Also, no encryption is currently enabled. Now Whoops, accidentally sent the message before finishing it. As I was going to say, the idea of not having the delimiters correct has some merit as I wouldn't know either way. How can I check or set them? Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash scripting question - simple regular expression?
Wow. I didn't know bash had arrays. Kool. :-) jipe wrote: On Sat, 11 Jan 2003 17:56:16 -0800 Jim C [EMAIL PROTECTED] wrote: I have a list of positive integers of which I only want the first one. They are of arbitrary size. How can I cut the rest of them off? I've been trying to write a regular expression for this using sed or awk. bash you said, so use only bash. array=($(your_command_to_create_the list_of_intergers)) echo ${array[0]} this displays the 1rst integer from your list. echo ${#array[*]} displays the number of integers echo ${array[$((${#array[*]}-1))]} displays the last integer etc... maybe you'll have to set IFS. depends of the separator. bye jipe Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash scripting question - simple regular expression?
Great but now I have another problem. What I am trying to do is create a sort of virtual file. I've already tried using the here document and it doesn't seem to be working for me. What I am trying to do exactly is create an LDIF file for passing to an LDAP database. I have each line stored in an individual shell variable like so: line1=dn: uid=$1,ou=Computers,dc=microverse,dc=net; line2=objectClass: top line3=objectClass: account line4=objectClass: posixAccount line5=uidNumber: $store line6=uid: $1 line7=cn: $1 line8=gidNumber: $groupnum line9=homeDirectory: /dev/null line10=loginShell: /bin/false line11=gecos: Machine Account line12=description: Machine Account The syntax I've been trying looks like this: ldapadd -x -D $binddn -w placepasswordhere hrdoc line1=dn: uid=$1,ou=Computers,dc=microverse,dc=net; line2=objectClass: top line3=objectClass: account line4=objectClass: posixAccount line5=uidNumber: $store line6=uid: $1 line7=cn: $1 line8=gidNumber: $groupnum line9=homeDirectory: /dev/null line10=loginShell: /bin/false line11=gecos: Machine Account line12=description: Machine Account hrdoc I've also tried it with newlines at the end of each line like so: ldapadd -x -D $binddn -w placepasswordhere hrdoc line1=dn: uid=$1,ou=Computers,dc=microverse,dc=net\n; line2=objectClass: top\n line3=objectClass: account\n line4=objectClass: posixAccount\n line5=uidNumber: $store\n line6=uid: $1\n line7=cn: $1\n line8=gidNumber: $groupnum\n line9=homeDirectory: /dev/null\n line10=loginShell: /bin/false\n line11=gecos: Machine Account\n line12=description: Machine Account\n hrdoc In all cases the here document doesn't seem to make it to the ldapadd command which I know reads from standard-in. I've also tried the -f switch which is for specifiying a filename. Anybody got a clue here? jipe wrote: On Sun, 12 Jan 2003 09:15:50 -0800 Mark Alexander [EMAIL PROTECTED] wrote: On Sat, Jan 11, 2003 at 05:56:16PM -0800, Jim C wrote: I have a list of positive integers of which I only want the first one. They are of arbitrary size. How can I cut the rest of them off? I've been trying to write a regular expression for this using sed or awk. #!/bin/sh LIST=42 666 1776 2001 echo $LIST | sed -e 's/^\([0-9]*\).*/\1/' LIST=42 666 1776 2001 echo ${LIST%% *} -- 42 or LIST=(42 666 1776 2001) echo ${LIST[0]} -- 42 both are about 5 times faster than a pipe with sed. bye jipe Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash scripting question - simple regular expression?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Jim C wrote on Mon, Jan 13, 2003 at 10:16:41AM -0800 : What I am trying to do is create a sort of virtual file. I've already tried using the here document and it doesn't seem to be working for me. What I am trying to do exactly is create an LDIF file for passing to an LDAP database. I have each line stored in an individual shell variable like so: There are two ways to do this: 1) Create an ldif file, then call ldap* with that ldif file. 2) Just pass it all to ldap* on stdin. The syntax I've been trying looks like this: ldapadd -x -D $binddn -w placepasswordhere hrdoc line1=dn: uid=$1,ou=Computers,dc=microverse,dc=net; line2=objectClass: top snip Look at this: #!/bin/bash cat $1.ldif hrdoc dn: uid=$1,ou=Computers,dc=microverse,dc=net objectClass: top objectClass: account objectClass: posixAccount uidNumber: $store uid: $1 cn: $1 gidNumber: $groupnum homeDirectory: /dev/null loginShell: /bin/false gecos: Machine Account description: Machine Account hrdoc Then you just do 'ldapadd -x -f $1.ldif blah blah blah' In all cases the here document doesn't seem to make it to the ldapadd command which I know reads from standard-in. All you gotta do is change the command portion of the above that I quoted: #!/bin/bash ldapadd -x blah blah blah hrdoc dn: uid=$1,ou=Computers,dc=microverse,dc=net objectClass: top objectClass: account objectClass: posixAccount uidNumber: $store uid: $1 cn: $1 gidNumber: $groupnum homeDirectory: /dev/null loginShell: /bin/false gecos: Machine Account description: Machine Account hrdoc Blue skies... Todd - -- MandrakeSoft USA http://www.mandrakesoft.com Mandrake: An amalgam of good ideas from RedHat, Debian, and MandrakeSoft. All in all, IMHO, an unbeatable combination. --Levi Ramsey on Cooker ML Cooker Version mandrake-release-9.1-0.1mdk Kernel 2.4.20-2mdk -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE+Iy/Ylp7v05cW2woRAhwMAJoDELaI+O82WNuz5SRnujaXG5y7hQCfUdlY dCj3ZneaqniZkaaADmAFVD4= =O07o -END PGP SIGNATURE- Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash scripting question - simple regular expression?
The are already sorted. I just need the largest one which is the first one. Mark Weaver wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Saturday 11 January 2003 08:56 pm, Jim C wrote: I have a list of positive integers of which I only want the first one. They are of arbitrary size. How can I cut the rest of them off? I've been trying to write a regular expression for this using sed or awk. without sorting them or anything why not just use a while loop with a counter? Mark -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE+IM23JuZ1geTzHgERAmKPAKDSouh+GrtkZTPj9o5CDvTG7tIEtgCgjOZk buhxrkvmzeqXdrW7n0a8ACk= =Mw7P -END PGP SIGNATURE- Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash scripting question - simple regular expression?
On Saturday 11 January 2003 08:56 pm, Jim C wrote: I have a list of positive integers of which I only want the first one. They are of arbitrary size. How can I cut the rest of them off? I've been trying to write a regular expression for this using sed or awk. you don't specify the format of the integers. are they space separated and all on one line? or are they line separated (each integer on its own line)? are there blank spaces (if the first) or blank lines (if the second) before the first integer? Blank spaces are between the numbers. or are they in some other format? you say they're arbitrary size, so does that mean they aren't in some fixed column format?\ No fixed columns. What they are is a line of userids with spaces between them. if they're one integer to a line, then head (for the first), tail (for the last), or some combination of head and tail (for anything in between) will get you the integer you want. There is only one line... but that is a good idea. I might be able to arrange for them to be in one column. Then I could use head. :-) I'll try that and let you know. if they're delimited by something (spaces, commas, colons, whatever), then cut -f fldnumber -d delimiter might help. otherwise, well, sed, awk, or some custom program in your favorite language. sed and awk are driving me nuts. ;-) if there are blank lines or blank fields before the first number, then some sort of bash while loop would be needed to ignore the blank lines or blank fields, print the first non-blank field, and then exit the loop. Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash scripting question - simple regular expression?
I have a list of positive integers of which I only want the first one. They are of arbitrary size. How can I cut the rest of them off? I've been trying to write a regular expression for this using sed or awk. you don't specify the format of the integers. are they space separated and all on one line? or are they line separated (each integer on its own line)? are there blank spaces (if the first) or blank lines (if the second) before the first integer? Blank spaces are between the numbers. In awk is pretty simple, just do: awk '{ print $1 }' filename (where filename is the name of the file with the numbers) I'm assuming you have only one line in that file, if you have more than one line and you want to specify which line to print do: awk '{ if ( NR==line_number ) print $1 } filename -- Toshiro Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash scripting question - simple regular expression?
On Sat, Jan 11, 2003 at 05:56:16PM -0800, Jim C wrote: I have a list of positive integers of which I only want the first one. They are of arbitrary size. How can I cut the rest of them off? I've been trying to write a regular expression for this using sed or awk. #!/bin/sh LIST=42 666 1776 2001 echo $LIST | sed -e 's/^\([0-9]*\).*/\1/' Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash scripting question - simple regular expression?
On Sat, 11 Jan 2003 17:56:16 -0800 Jim C [EMAIL PROTECTED] wrote: I have a list of positive integers of which I only want the first one. They are of arbitrary size. How can I cut the rest of them off? I've been trying to write a regular expression for this using sed or awk. bash you said, so use only bash. array=($(your_command_to_create_the list_of_intergers)) echo ${array[0]} this displays the 1rst integer from your list. echo ${#array[*]} displays the number of integers echo ${array[$((${#array[*]}-1))]} displays the last integer etc... maybe you'll have to set IFS. depends of the separator. bye jipe Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash scripting question - simple regular expression?
On Sun, 12 Jan 2003 09:15:50 -0800 Mark Alexander [EMAIL PROTECTED] wrote: On Sat, Jan 11, 2003 at 05:56:16PM -0800, Jim C wrote: I have a list of positive integers of which I only want the first one. They are of arbitrary size. How can I cut the rest of them off? I've been trying to write a regular expression for this using sed or awk. #!/bin/sh LIST=42 666 1776 2001 echo $LIST | sed -e 's/^\([0-9]*\).*/\1/' LIST=42 666 1776 2001 echo ${LIST%% *} -- 42 or LIST=(42 666 1776 2001) echo ${LIST[0]} -- 42 both are about 5 times faster than a pipe with sed. bye jipe Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
[expert] bash scripting question - simple regular expression?
I have a list of positive integers of which I only want the first one. They are of arbitrary size. How can I cut the rest of them off? I've been trying to write a regular expression for this using sed or awk. Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash scripting question - simple regular expression?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Saturday 11 January 2003 08:56 pm, Jim C wrote: I have a list of positive integers of which I only want the first one. They are of arbitrary size. How can I cut the rest of them off? I've been trying to write a regular expression for this using sed or awk. without sorting them or anything why not just use a while loop with a counter? Mark -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE+IM23JuZ1geTzHgERAmKPAKDSouh+GrtkZTPj9o5CDvTG7tIEtgCgjOZk buhxrkvmzeqXdrW7n0a8ACk= =Mw7P -END PGP SIGNATURE- Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash scripting question - simple regular expression?
On Saturday 11 January 2003 08:56 pm, Jim C wrote: I have a list of positive integers of which I only want the first one. They are of arbitrary size. How can I cut the rest of them off? I've been trying to write a regular expression for this using sed or awk. you don't specify the format of the integers. are they space separated and all on one line? or are they line separated (each integer on its own line)? are there blank spaces (if the first) or blank lines (if the second) before the first integer? or are they in some other format? you say they're arbitrary size, so does that mean they aren't in some fixed column format? if they're one integer to a line, then head (for the first), tail (for the last), or some combination of head and tail (for anything in between) will get you the integer you want. if they're delimited by something (spaces, commas, colons, whatever), then cut -f fldnumber -d delimiter might help. otherwise, well, sed, awk, or some custom program in your favorite language. if there are blank lines or blank fields before the first number, then some sort of bash while loop would be needed to ignore the blank lines or blank fields, print the first non-blank field, and then exit the loop. tiger -- Gerald Timothy Quimpo tiger*quimpo*org gquimpo*sni-inc.com tiger*sni*ph Public Key: gpg --keyserver pgp.mit.edu --recv-keys 672F4C78 Veritas liberabit vos. Doveryai no proveryai. Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
[expert] Bash scripts: Displaying output of command and testing in same line?
I'm a newbie trying to create a bash script. (I'm not sure whether this is a newbie level question or not.) I'd like to run a command (almost anything) in an if statement and direct it's normal output to standard out but also test that output using grep to use the result in the logic of the script. For example, the output of mailq is Mail queue is empty if the mail queue is empty, and a list of messages if there are any in the queue. In butchered pseudocode, I'd like to do something like this: * run mailq displaying output * if mailq was empty (tested like: mailq | grep -c empty) do something else do something else fi I could do something like run mailq and capture the output in a file or variable, then: * print the file or variable * test the file or variable Or, I could run the command twice, but I want to avoid that. I thought there might be an easier way (or a one liner type approach, which while it might be one line might be fairly difficult (for me) to understand ;-) I've started trying variations of the following, but I'm really just shooting in the dark: if mailq tee grep -c empty Randy Kramer Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] Bash scripts: Displaying output of command and testingin same line?
On Thu, 22 Aug 2002, Randy Kramer wrote: I'm a newbie trying to create a bash script. (I'm not sure whether this is a newbie level question or not.) I'd like to run a command (almost anything) in an if statement and direct it's normal output to standard out but also test that output using grep to use the result in the logic of the script. There are several approaches you could take, all depending on the length of output and what else you'd need to do with it. One approach that you've found is to redirect the output to a temporary file: somecommand tmpfile.$$ The $$ expands to the process ID of the command and is useful for quickly generating a filename. You can then parse the file with sed, awk, or whatever you need. For example, the output of mailq is Mail queue is empty if the mail queue is empty, and a list of messages if there are any in the queue. In butchered pseudocode, I'd like to do something like this: * run mailq displaying output * if mailq was empty (tested like: mailq | grep -c empty) do something else do something else fi I could do something like run mailq and capture the output in a file or variable, then: * print the file or variable * test the file or variable Or, I could run the command twice, but I want to avoid that. Yes, definitely avoid this. The output may change between runs. I thought there might be an easier way (or a one liner type approach, which while it might be one line might be fairly difficult (for me) to understand ;-) Look through the bash conditional operators. There's a ?: operator that may do what you need. I've started trying variations of the following, but I'm really just shooting in the dark: if mailq tee grep -c empty You're missing the pipe '|' between commands. Randy Kramer Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
[expert] Bash the Path
Hi I am having a problem persuading Bash to accept a script to add some additional environment variable to a Konsole environment. The script I am using simply adds some stuff to the PATH statement as well as some extra environment variables typically the file contains statements as follows. PATH=$VARKON_ROOT/bin:$PATH export PATH In previous versions of UNIX I have used making the script file executable and running it resulted in the PATH (in this case) having the additional directory appended to it, this also worked for new environment variables. When I do the same thing in Linux in a Konsole terminal under KDE the environment does not change. As far as I can glean from reading the man page for Bash this should work. If I run the commands from the prompt everything works fine but of course this is tedious and should not be necessary. Can anyone guide me as what I am doing wrong? Colin Close [EMAIL PROTECTED] Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] Bash the Path
try ... source [pathtoscript/]scriptname (where [pathtoscript/] is the optional path to the script) This is because each script gets it's own bash (or other shell) interpreter, so the environment values go into the sub shells environment, no the shell being run under konsole. BTW: I'm pretty sure this is how other unix variants work as well... On Wed, 2002-05-22 at 10:02, C.H. Close wrote: Hi I am having a problem persuading Bash to accept a script to add some additional environment variable to a Konsole environment. The script I am using simply adds some stuff to the PATH statement as well as some extra environment variables typically the file contains statements as follows. PATH=$VARKON_ROOT/bin:$PATH export PATH In previous versions of UNIX I have used making the script file executable and running it resulted in the PATH (in this case) having the additional directory appended to it, this also worked for new environment variables. When I do the same thing in Linux in a Konsole terminal under KDE the environment does not change. As far as I can glean from reading the man page for Bash this should work. If I run the commands from the prompt everything works fine but of course this is tedious and should not be necessary. Can anyone guide me as what I am doing wrong? Colin Close [EMAIL PROTECTED] Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com -- -- Edward Muller - Director of Information Services LearningPatterns.com Inc. Mobile: 973.715.0230 NYC: 212.487.9064 x115 Email/Jabber: [EMAIL PROTECTED] http://www.learningpatterns.com Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] Bash the Path
On Wed, 22 May 2002, C.H. Close wrote: Hi I am having a problem persuading Bash to accept a script to add some additional environment variable to a Konsole environment. The script I am using simply adds some stuff to the PATH statement as well as some extra environment variables typically the file contains statements as follows. PATH=$VARKON_ROOT/bin:$PATH export PATH In previous versions of UNIX I have used making the script file executable and running it resulted in the PATH (in this case) having the additional directory appended to it, this also worked for new environment variables. When I do the same thing in Linux in a Konsole terminal under KDE the environment does not change. As far as I can glean from reading the man page for Bash this should work. If I run the commands from the prompt everything works fine but of course this is tedious and should not be necessary. Can anyone guide me as what I am doing wrong? Most likely you're executing the script rather than sourcing it. E.g., doing: ./name_of_script rather than: . ./name_of_script By sourcing it, you run the script in the current shell rather than in a subshell, whose environment is lost on exit. Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] Bash the Path
Edward Muller wrote: try ... source [pathtoscript/]scriptname (where [pathtoscript/] is the optional path to the script) This is because each script gets it's own bash (or other shell) interpreter, so the environment values go into the sub shells environment, no the shell being run under konsole. BTW: I'm pretty sure this is how other unix variants work as well... You are right for both the korn and bourne shells, and that does cover a lot of unix drjung -- J. Craig Woods UNIX/NT Network/System Administration http://www.trismegistus.net/resume.html Character is built upon the debris of despair --Emerson Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] Bash the Path
C.H. Close wrote: Hi I am having a problem persuading Bash to accept a script to add some additional environment variable to a Konsole environment. The script I am using simply adds some stuff to the PATH statement as well as some extra environment variables typically the file contains statements as follows. PATH=$VARKON_ROOT/bin:$PATH export PATH In previous versions of UNIX I have used making the script file executable and running it resulted in the PATH (in this case) having the additional directory appended to it, this also worked for new environment variables. When I do the same thing in Linux in a Konsole terminal under KDE the environment does not change. As far as I can glean from reading the man page for Bash this should work. If I run the commands from the prompt everything works fine but of course this is tedious and should not be necessary. Can anyone guide me as what I am doing wrong? Colin Close [EMAIL PROTECTED] Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com Ummm you can unset DISPLAY in a terminal window and still use the GUI on the main screen. This is not accidental. If you want to change the PATH for a user, then put the path in ~/.bashrc or ~/.bashprofile, or source (the file where your PATH is set) inside scripts that need it. Then the default is there for the user at login, else the changes to environment have a window as their scope (how else could it be and multitask properly?). Civileme Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] Bash the Path
On Wed, 2002-05-22 at 04:02, C.H. Close wrote: Hi I am having a problem persuading Bash to accept a script to add some additional environment variable to a Konsole environment. The script I am using simply adds some stuff to the PATH statement as well as some extra environment variables typically the file contains statements as follows. PATH=$VARKON_ROOT/bin:$PATH export PATH In previous versions of UNIX I have used making the script file executable and running it resulted in the PATH (in this case) having the additional directory appended to it, this also worked for new environment variables. When I do the same thing in Linux in a Konsole terminal under KDE the environment does not change. As far as I can glean from reading the man page for Bash this should work. If I run the commands from the prompt everything works fine but of course this is tedious and should not be necessary. Can anyone guide me as what I am doing wrong? Colin Close [EMAIL PROTECTED] All it should take, I think, is to source the file instead of just running it. Do a man bash and / (that's search) source Gary Dunn Open Slate Project Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] Bash the Path
[EMAIL PROTECTED] wrote: On Wed, 22 May 2002, C.H. Close wrote: Hi I am having a problem persuading Bash to accept a script to add some additional environment variable to a Konsole environment. The script I am using simply adds some stuff to the PATH statement as well as some extra environment variables typically the file contains statements as follows. PATH=$VARKON_ROOT/bin:$PATH export PATH In previous versions of UNIX I have used making the script file executable and running it resulted in the PATH (in this case) having the additional directory appended to it, this also worked for new environment variables. When I do the same thing in Linux in a Konsole terminal under KDE the environment does not change. As far as I can glean from reading the man page for Bash this should work. If I run the commands from the prompt everything works fine but of course this is tedious and should not be necessary. Can anyone guide me as what I am doing wrong? Most likely you're executing the script rather than sourcing it. E.g., doing: ./name_of_script rather than: . ./name_of_script Hi, Most grateful for your help this worked perfectly I was indeed using ./name_of_script. The Bash man page is very large and I and I must have missed the relevant part. While investigating this problem I came across a bug in the graphical log in manager. Try the following (assumes that you using the auto login feature) open a Konsole and run env to see your environment and check the PATH statement. Log out and then log in again via the graphical login open console again and run env again and check your PATH statement on my system (8.1) the PATH statement has had the original path appended to it a second time some additional colons and forward slashes seem to appear as well during the cocatanation. Here is an example from my system: After logout and login PATH=/usr//bin:/bin:/usr/bin::/usr/local/bin:/usr/X11R6/bin:/usr/X11R6/bin:/usr/games Does anyone else get the same problem? My thanks to all others who replied. Colin Close [EMAIL PROTECTED] Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] BASH Scripts - Thankyou
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 After suggestion from one of you guys (forgot the name and have deleted the mail - sorry) i have started to use the dynamic dns of no-ip.com, this is a really great system. Thanks Tom -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE8fjNfXCpWOla2mCcRApl7AJ4xMj+zV4GM+SG8iVEx/+QJ0zraMgCeKVlC qQThfAnsQF16L9vM2pZyjvg= =IVIM -END PGP SIGNATURE- Want to buy your Pack or Services from MandrakeSoft? Go to http://wwwmandrakestorecom
RE: [expert] BASH Scripts
yeah, I use ddclient with dyndns.org same deal, and it emails root, (or whomever roots alias is) with the details of the ip address whenever the machine reconnects, I run my mailserver at home like that. works great, and I always have an email with the new IP in it. rgds Frank -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of David Guntner Sent: Thursday, 28 February 2002 7:18 AM To: [EMAIL PROTECTED] Subject: Re: [expert] BASH Scripts Tom Badran grabbed a keyboard and wrote: How can i use an if in a bash script so that it will only run commands if the specified file is empty? Basically, ive set up a cache system by which the output of ifconfig is stored in /var/cache/IP/1 Then, every minute my script is run. It first puts the output of ifconfig in /var/cache/IP/2 and diff's it with 1 outputing that to a file 'diff'. I then want to run a series of commands if the file diff is not empty. if [ -s diff ]; then {do your command or commands here} fi What im trying to do is get an email sent to me every time the IP changes on a specific machine, so i always have a record of it for logging in via ssh. The specific connection is ppp0 which auto redials on disconnect. If there is an easier way of doing this please share with me. Have you checked out the free DDNS service at no-ip.com? They have a Linux client that you can run when you connect, and then you can just ssh into yourmachine.no-ip.com instead of worrying about the current IP address. --Dave -- David Guntner GEnie: Just say NO! http://www.akaMail.com/pgpkey/davidg or key server for PGP Public key Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] BASH Scripts - Thankyou
Tom Badran grabbed a keyboard and wrote: After suggestion from one of you guys (forgot the name and have deleted the mail - sorry) i have started to use the dynamic dns of no-ipcom, this is a really great system Thanks That was me And you're welcome :-) --Dave -- David Guntner GEnie: Just say NO! http://wwwakaMailcom/pgpkey/davidg or key server for PGP Public key Want to buy your Pack or Services from MandrakeSoft? Go to http://wwwmandrakestorecom
Re: [expert] BASH Scripts - Thankyou
I do not have an adsl connection, but a ppp dialup, but some of the solutions I use here may be applicable: The system I use is run from etc/ppp/ip-uplocal, a file that is run automatically when a ppp connection comes up - there are also network scripts that run when other interfaces come online: 1) The file contains $IPLOCAL and $IPREMOTE variables already set via the network scripts (by parsing ifconfig results I think) 2) uses the info to change the IP at dyndns and ods via ez-ipupdate 3) creates a simple web page containing date/time and IP numbers and ftp's it up to my webspace on the ISP's server 4) kicks ntpd which since 81 occaisionally hangs and refuses to recognise a new connection 5) restarts the firewall with the latest IP 6) same with named - not strictly neccessary, but solved some undefined, not quite working right type problems if you know what I mean!! 7) sends a smb message (winpopup) to the windoze machines attached telling them the connection is back up A similar script in ip-downlocal tells them when the ISP logs the connection off (kicker) 8) Recently I added some stuff to separate the ISP ppp connection and my laptop using another ppp connection through a serial port on the same machine From experience, I have found the redundancy of two dynamic dns systems and a separate web page is well worth while! BillK On Fri, 2002-03-01 at 00:53, Praedor Tempus wrote: Just some noiseI am late getting to this and in the past I had this desire too (to be informed every time my ip address changed) All I did was have a cronjob send me a simple email every 30 minutes (or so, depending on what I determined my renewal period was) The email didn't even need to contain any information because what I was interested in were the headers I'd get the email and check the headers see my ip address and could therefore see if my address had changed Want to buy your Pack or Services from MandrakeSoft? Go to http://wwwmandrakestorecom
Re: [expert] BASH Scripts - Thankyou
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Thursday 28 Feb 2002 5:43 pm, you wrote: Tom Badran grabbed a keyboard and wrote: After suggestion from one of you guys (forgot the name and have deleted the mail - sorry) i have started to use the dynamic dns of no-ip.com, this is a really great system. Thanks That was me. And you're welcome. :-) Then ill thank you directly, Cheers! Tom -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE8fnYYXCpWOla2mCcRAktOAKC0tBvD7QRD//HGXwhM63ioxzODSgCgt1zO 57Cy1X6iot7zjrYM2qZVjjA= =UtrS -END PGP SIGNATURE- Want to buy your Pack or Services from MandrakeSoft? Go to http://wwwmandrakestorecom
[expert] BASH Scripts
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 How can i use an if in a bash script so that it will only run commands if the specified file is empty? Basically, ive set up a cache system by which the output of ifconfig is stored in /var/cache/IP/1 Then, every minute my script is run. It first puts the output of ifconfig in /var/cache/IP/2 and diff's it with 1 outputing that to a file 'diff'. I then want to run a series of commands if the file diff is not empty. What im trying to do is get an email sent to me every time the IP changes on a specific machine, so i always have a record of it for logging in via ssh. The specific connection is ppp0 which auto redials on disconnect. If there is an easier way of doing this please share with me. Thanks Tom -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE8fWUSXCpWOla2mCcRAmyuAJ0dNeH725n8jc0UhaeIYgdxlerG3wCfQwtM mEDR987gtUilwovjGKbV3b8= =IODe -END PGP SIGNATURE- Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] BASH Scripts
Tom Badran grabbed a keyboard and wrote: How can i use an if in a bash script so that it will only run commands if the specified file is empty? Basically, ive set up a cache system by which the output of ifconfig is stored in /var/cache/IP/1 Then, every minute my script is run. It first puts the output of ifconfig in /var/cache/IP/2 and diff's it with 1 outputing that to a file 'diff'. I then want to run a series of commands if the file diff is not empty. if [ -s diff ]; then {do your command or commands here} fi What im trying to do is get an email sent to me every time the IP changes on a specific machine, so i always have a record of it for logging in via ssh. The specific connection is ppp0 which auto redials on disconnect. If there is an easier way of doing this please share with me. Have you checked out the free DDNS service at no-ip.com? They have a Linux client that you can run when you connect, and then you can just ssh into yourmachine.no-ip.com instead of worrying about the current IP address. --Dave -- David Guntner GEnie: Just say NO! http://www.akaMail.com/pgpkey/davidg or key server for PGP Public key Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] BASH Scripts
Tom Badran [EMAIL PROTECTED] wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 How can i use an if in a bash script so that it will only run commands if the specified file is empty? Basically, ive set up a cache system by which the output of ifconfig is stored in /var/cache/IP/1 Then, every minute my script is run. It first puts the output of ifconfig in /var/cache/IP/2 and diff's it with 1 outputing that to a file 'diff'. I then want to run a series of commands if the file diff is not empty. What im trying to do is get an email sent to me every time the IP changes on a specific machine, so i always have a record of it for logging in via ssh. The specific connection is ppp0 which auto redials on disconnect. If there is an easier way of doing this please share with me. One way to do it is this sort of hack: [rustyc@fw rustyc]$ cat bin/watchmail #!/bin/bash foo=`ls -l /var/spool/mail/rustyc` while : ; do for j in 1 2 3 4 5 6 7 8 ; do for i in 1 2 3 4 5 6 7 8 9 0 ; do if [ `ls -l /var/spool/mail/rustyc` = $foo ] ; then echo -n '.' sleep 30 else echo echo `date` #echo Was $foo echo `ls -l /var/spool/mail/rustyc` foo=`ls -l /var/spool/mail/rustyc` egrep '^Subject' /var/spool/mail/rustyc | tail -2 sleep 30 fi done #date #; echo -n '.'~/rnlog done echo #echo -n `date ; ls -l /var/spool/mail/rustyc` done (that script watches for a change to file /var/spool/mail/rustyc and shows the change (and a few lines from the file) when it does - sort of a poor man's textual biff ;-) The key lines are: foo=`ls -l /var/spool/mail/rustyc` while : ; do if [ `ls -l /var/spool/mail/rustyc` = $foo ] ; then # no change else # file has changed fi done On the other hand, diff will return nonzero return status if the files are different, so you can just say something like: diff foo1 foo2 if [ $? -eq 0] ; then # no change else # change fi (Assuming I'm remembering the syntax for 'return status from last command' right, if not I'm sure someone will fix this for us ;-) rc Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] BASH Scripts
On Wed, 27 Feb 2002, Tom Badran wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 How can i use an if in a bash script so that it will only run commands if the specified file is empty? Basically, ive set up a cache system by which the output of ifconfig is stored in /var/cache/IP/1 Then, every minute my script is run. It first puts the output of ifconfig in /var/cache/IP/2 and diff's it with 1 outputing that to a file 'diff'. I then want to run a series of commands if the file diff is not empty. What im trying to do is get an email sent to me every time the IP changes on a specific machine, so i always have a record of it for logging in via ssh. The specific connection is ppp0 which auto redials on disconnect. If there is an easier way of doing this please share with me. The only problem I see with using the raw output from ifconfig is that the RX and TX fields will always be different. If you were to parse the output of ifconfig to return only the IP address before writing it to the file, you could then just compare the current IP against a 'cat' of the old IP. I.e. IP=`ifconfig eth0|grep inet addr|cut -d: -f2|cut -d' ' -f1` (or something equally ugly) Then do something like: Old_IP=`cat $FILENAME` [ $IP == $OLD_IP ]; then do_something Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] BASH Scripts
Tom Badran wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 How can i use an if in a bash script so that it will only run commands if the specified file is empty? Basically, ive set up a cache system by which the output of ifconfig is stored in /var/cache/IP/1 Then, every minute my script is run. It first puts the output of ifconfig in /var/cache/IP/2 and diff's it with 1 outputing that to a file 'diff'. I then want to run a series of commands if the file diff is not empty. Well first, you can test the exit value of diff to see if there were differences: if diff /var/cache/IP/1 /var/cache/IP/2; then #commands for when files are the same else #commands for when files differ fi Or if you only care when they differ: if ! diff /var/cache/IP/1 /var/cache/IP/2; then #commands for when files differ fi If you really need to test for empty files, try: if [ -s filename ]; then #commands for when file is *not* empty else #commands for when file is empty fi Or if you only care for the empty ones: if [ ! -s filename ]; then #commands for when the file is empty fi -Kyle -- _ ---ooO( )Ooo--- Kyle J. McDonald (o o) Systems Support Engineer Sun Microsystems Inc.| Enterprise Server Products[EMAIL PROTECTED] 1 Network Drive BUR03-4630 \\\// voice: (781) 442-2184 Burlington, MA 01803 (o o)fax: (781) 442-1542 ---ooO(_)Ooo--- Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] BASH Scripts
Hi Tom, I wrote a shell script for the same purpose. Here it is: #!/bin/sh NewIP=`/sbin/ifconfig ppp0 | grep 'inet addr' | awk '{print $2}' \ | sed -e 's/.*://'` if [ -e /home/rjonasz/ip.txt ]; then OldIP=$(cat /home/rjonasz/ip.txt) else OldIP= fi if [ $OldIP != $NewIP ]; then echo $NewIP | mail -s Foucault's IP Address has changed! \ [EMAIL PROTECTED] echo $NewIP /home/rjonasz/ip.txt fi Hope this helps, Randy On Wed, 27 Feb 2002, Tom Badran wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 How can i use an if in a bash script so that it will only run commands if the specified file is empty? Basically, ive set up a cache system by which the output of ifconfig is stored in /var/cache/IP/1 Then, every minute my script is run. It first puts the output of ifconfig in /var/cache/IP/2 and diff's it with 1 outputing that to a file 'diff'. I then want to run a series of commands if the file diff is not empty. What im trying to do is get an email sent to me every time the IP changes on a specific machine, so i always have a record of it for logging in via ssh. The specific connection is ppp0 which auto redials on disconnect. If there is an easier way of doing this please share with me. Thanks Tom -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE8fWUSXCpWOla2mCcRAmyuAJ0dNeH725n8jc0UhaeIYgdxlerG3wCfQwtM mEDR987gtUilwovjGKbV3b8= =IODe -END PGP SIGNATURE- -- Under any conditions, anywhere, whatever you are doing, there is some ordinance under which you can be booked. -- Robert D. Sprecht, Rand Corp. Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re[2]: [expert] BASH Scripts
On Wed, 27 Feb 2002, Rusty Carruth wrote: There's probably much better ways to do this, but I got it working this way and have no plan to fix it ;-) Hey now, the very fabric of the Internet is stitched together with assorted hacks, workarounds, ugly scripts, we'll fix it later code, and suchlike bailing wire and duct tape! If people only knew... :D Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re[2]: [expert] BASH Scripts
[EMAIL PROTECTED] wrote: On Wed, 27 Feb 2002, Tom Badran wrote: What im trying to do is get an email sent to me every time the IP changes on a specific machine, so i always have a record of it for logging in via ssh. The specific connection is ppp0 which auto redials on disconnect. If there is an easier way of doing this please share with me. I.e. IP=`ifconfig eth0|grep inet addr|cut -d: -f2|cut -d' ' -f1` (or something equally ugly) Then do something like: Old_IP=`cat $FILENAME` [ $IP == $OLD_IP ]; then do_something Oh. Duh. If I'd read the email closer, I'd have posted THIS script instead: [root@fw antispam]# cat /etc/rc.d/init.d/what.a.hack #!/bin/bash newip=`/sbin/ifconfig ppp0 | /bin/egrep 'inet addr' | /bin/sed 's/inet addr://' | /bin/awk '{print $1}'` if [ .$newip = . ] ; then echo oops - newip is blank again # this happens more than I would like, one of these days I will figure out why. exit -1 fi oldip=`cat /tmp/current.ip` if [ $newip == $oldip ] ; then exit 0 ; fi echo $newip /etc/rc.d/init.d/iplog /bin/sed s/FARBOO/$newip/ /etc/rc.d/init.d/rc.fw.basehack /root/rc.hacko echo $newip /tmp/current.ip chmod 700 /root/rc.hacko /sbin/ipchains -L -n -v -x /root/rc.hacko echo $newip | elm [EMAIL PROTECTED] And I run that in a cron job. Here's my crontab entry: 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /etc/rc.d/init.d/what.a.hack Yeah, its quite a hack. But it does the trick of resetting my firewall rules whenever the ip addr changes, and it notifies me, and everything. There's probably much better ways to do this, but I got it working this way and have no plan to fix it ;-) rc Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] BASH Scripts
Rusty Carruth grabbed a keyboard and wrote: And I run that in a cron job. Here's my crontab entry: 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /etc/rc.d/init.d/what.a.hack Were you aware that you could just do: */5 * * * * /etc/rc.d/init.d/what.a.hack Which tells cron to run the job every 5 minutes? Just FYI. It'll save you some typing the next time you have to create a new cron job. :-) --Dave -- David Guntner GEnie: Just say NO! http://www.akaMail.com/pgpkey/davidg or key server for PGP Public key Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash is wiping out the last line that doesn't have a newline
tested your line in 8.1 [james@jamlin Winamp]$ echo -n I can see this line in Mandrake 7.2 but not 8.0 I can see this line in Mandrake 7.2 but not 8.0[james@jamlin Winamp]$ Works in 8.1 .. Don't have an 8.0 box to test it on. Perhaps upgrading bash to the 8.1 version, bash-2.05-10mdk might help. James On Sun, 13 Jan 2002 18:21:20 +1100 pesarif [EMAIL PROTECTED] wrote: Hello, Has anyone noticed this?: In Mandrake 7.2, [root@tux350 /root]# echo -n I can see this line in Mandrake 7.2 but not 8.0 I can see this line in Mandrake 7.2 but not 8.0[root@tux350 /root]# In Mandrake 8.0, [root@tux350 /root]# echo -n I can see this line in Mandrake 7.2 but not 8.0 [root@tux350 /root]# If the last line of output isn't terminated by a newline, then the bash prompt will get rid of it in Mandrake 8.0. I don't like this because some of my programs depend on bash _not_ killing the last line of output. Does anyone know how I can get the 7.2 behaviour back? Some setting in bash? Thanks in advance, pesarif Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] bash is wiping out the last line that doesn't have a newline
[james@jamlin Winamp]$ echo -n I can see this line in Mandrake 7.2 but not 8.0 I can see this line in Mandrake 7.2 but not 8.0[james@jamlin Winamp]$ Works in 8.1 .. Don't have an 8.0 box to test it on. Perhaps upgrading bash to the 8.1 version, bash-2.05-10mdk might help. More correctly, you can see the line, followed immediately by your bash prompt, until you type the next character. At that point bash erases the line and reprints your prompt along the character you just typed. At least that's the behavior on my machine. A really *ugly* work-around is to embed a newline at the beginning of your prompt string by using \n. It's ugly because under normal circumstances you get an extra empty line between prompts or between the last line of output and your prompt. /Pen Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
[expert] bash is wiping out the last line that doesn't have a newline
Hello, Has anyone noticed this?: In Mandrake 7.2, [root@tux350 /root]# echo -n I can see this line in Mandrake 7.2 but not 8.0 I can see this line in Mandrake 7.2 but not 8.0[root@tux350 /root]# In Mandrake 8.0, [root@tux350 /root]# echo -n I can see this line in Mandrake 7.2 but not 8.0 [root@tux350 /root]# If the last line of output isn't terminated by a newline, then the bash prompt will get rid of it in Mandrake 8.0. I don't like this because some of my programs depend on bash _not_ killing the last line of output. Does anyone know how I can get the 7.2 behaviour back? Some setting in bash? Thanks in advance, pesarif Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
[expert] Bash Questions SOLVED
For whatever reason MDK didn't create either the .bashrc or the .bash_profile in my home directory. I copied them from one of the other systems and tweaked a bit and BINGO bash works as expected. -- Ken Thompson, North West Antique Autos Payette, Idaho Email: [EMAIL PROTECTED] http://www.nwaa.com Sales and brokering of antique autos and parts. Linux- Coming Soon To A Desktop Near You Registered Linux User #183936 Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
[expert] Bash Questions
Hi gang, I have MKD 8.1 installed on 3 different machines, different MoBo's, mem, vid etc. My question is, on my Athalon 1.2Ghz, ePox 8KTA3 MoBo, 512 RAM, Matrox Millenium 450, the prompt in bash is bash-2.05$ and the delete key is also the back space instead of delete. If I try to delete during a session I get a system beep and a tilde, no back space. If I press the delete key with only 1 or 2 letters or whatever it is the same as the back space key. On the other machines bash works as expected and the prompt shows user@hostname$. I installed all the systems the same as far as I can remember, nothing special or exotic mostly just package selection. I didn't make any choices in the shell selection, it's the default setup here. What could have gone wrong and what can I do about it? OH, if I'm not using a term window, ie ctrl +alt+Fn, I get the expected bash prompt and behavior -- Ken Thompson, North West Antique Autos Payette, Idaho Email: [EMAIL PROTECTED] http://www.nwaa.com Sales and brokering of antique autos and parts. Linux- Coming Soon To A Desktop Near You Registered Linux User #183936 Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [expert] BASH
Can i make bash ask me - when i use rm -rf. remove the f ! if that doesn't work, try 'unalias rm' Thomas.
Re: [expert] BASH
Can i make bash ask me - when i use rm -rf. If you logon a shell, typically the shell will a file called, say, .bashrc, in your home directory. Most of the linux distribution alias rm to rm -i if the user is root. man rm you will see. Yours, Simon.
[expert] BASH
Can i make bash ask me - when i use rm -rf. ___ Mvh./Yours sincerely Lars Lars Roland Kristiansen | Email:[EMAIL PROTECTED] Stud. Scient. Mathematics | TLF(home):39699914 - 116 Copenhagen University - | Home address: Bispebjerg parkalle Institute for Mathematical Sciences | 22 - 2400 københavn NV - room 116. Url: www.math.ku.dk | Politics is for the moment, equations are forever - Albert Einstein
Re: [expert] BASH Arithmetic Evaluation
SoloCDM wrote: I tried to evaluate an arithmetic value with a while command using "while [ ${MANS} = 4 ]", but it doesn't work . . . why? Ignore the omittance of do through done. Try using the bash arithmetic test operators. i=8;while [ $i -ge 4 ] ; do let i-=1; echo $i;done ; -Mark -- Mark Belanger LTX Corporation
[expert] BASH Arithmetic Evaluation
I tried to evaluate an arithmetic value with a while command using "while [ ${MANS} = 4 ]", but it doesn't work . . . why? Ignore the omittance of do through done. Note: When you reply to this message, please include the mailing list/newsgroup address in Cc: and my email address in To:. * Signed, SoloCDM
Re: [expert] bash command line editing broken for several releases
Tom Berkley wrote: No problem here with editing command lines. Sometimes when I have problems installing new updates I will have an rpm -Fvh ..rpm line that is 8 or ten lines long in a large display window. Never over a two year period had one problem with line editing, removing several filenames, adding more. What terminal are you running? xterm (version)? kde-xterm, gnome-xterm, straight video display? And what is your $TERM variable set to? duane
[expert] bash command line editing broken for several releases
Have others here also had the problem where editing a long command line using bash (in vi mode) within an xterm causes the command line to get all screwed up? This began for me back with 7.0 (I think) and still isn't fixed. The problem might depend on resized xterm windows that were at one time wider than 80 columns or wider than their initial size. duane
Re: [expert] bash command line editing broken for several releases
Have others here also had the problem where editing a long command line using bash (in vi mode) within an xterm causes Yes, I had that problem just last night. might depend on resized xterm windows that were at one time wider than 80 columns or wider than their initial size. This was the case in the instance I'm referring to. I was busy and so didn't investigate and it was the first time it has happened to me. Cheers --- Larry
Re: [expert] bash command line editing broken for several releases
No problem here with editing command lines. Sometimes when I have problems installing new updates I will have an rpm -Fvh ..rpm line that is 8 or ten lines long in a large display window. Never over a two year period had one problem with line editing, removing several filenames, adding more. duane voth wrote: Have others here also had the problem where editing a long command line using bash (in vi mode) within an xterm causes the command line to get all screwed up? This began for me back with 7.0 (I think) and still isn't fixed. The problem might depend on resized xterm windows that were at one time wider than 80 columns or wider than their initial size. duane
[expert] Bash prompt
Hello, I recently did something to my system (don't know what yet!), and it seems that a number of things suddenly got changed, like my ethernet card aliases. No problem, fixed that up. However, when I log in with Telnet, I get: bash-2.04$ Instead of: [bob@r0 bob]$ (Meaning user BOB at machine R0 in directory BOB) If I SU, it looks correct. What got messed up, and what file affects this? Bob
Re: [expert] Bash prompt
I think ur missing the .bashrc file in ur home directory Cheers Sridhar - Original Message - From: "Bob Puff@NLE" [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, August 12, 2000 9:42 PM Subject: [expert] Bash prompt Hello, I recently did something to my system (don't know what yet!), and it seems that a number of things suddenly got changed, like my ethernet card aliases. No problem, fixed that up. However, when I log in with Telnet, I get: bash-2.04$ Instead of: [bob@r0 bob]$ (Meaning user BOB at machine R0 in directory BOB) If I SU, it looks correct. What got messed up, and what file affects this? Bob
[expert] Bash Scripting
I'm interested in learning a little about bash scripting. In particular, I'd like to learn how to tell if the user logging on is logging in under X or from a command prompt. Can anyone point me in the direction of where I can find this information? Thanks... -Chris
Re: [expert] Bash Scripting
Necrotica wrote: I'm interested in learning a little about bash scripting. In particular, I'd like to learn how to tell if the user logging on is logging in under X or from a command prompt. Can anyone point me in the direction of where I can find this information? Thanks... -Chris printenv from Konsole when you are logged in in graphics mode printenv from a console (logged in on runlevel 3) Check the settings of the DISPLAY variable Civileme
Re: [expert] Bash Scripting
Civileme wrote: Necrotica wrote: I'm interested in learning a little about bash scripting. In particular, I'd like to learn how to tell if the user logging on is logging in under X or from a command prompt. Can anyone point me in the direction of where I can find this information? Thanks... -Chris printenv from Konsole when you are logged in in graphics mode printenv from a console (logged in on runlevel 3) Check the settings of the DISPLAY variable Civileme Ummm... Well under the console perhaps better to printenv | less (blush). That fills more than a screen! The point is DISPLAY has a value in graphics mode and does NOT exist in console So if [ $DISPLAY ] then # DISPLAY is set and is a nonzero length string so do GUI stuff elif [ -z $DISPLAY ] # do the console stuf here (length of string is zero) else # do any other stuff here fi Civileme
Re: [expert] Bash Scripting
Thanks for the help, guys. That was exactly what I was looking for! -Chris On Sat, 10 Jun 2000, Civileme wrote: Civileme wrote: Necrotica wrote: I'm interested in learning a little about bash scripting. In particular, I'd like to learn how to tell if the user logging on is logging in under X or from a command prompt. Can anyone point me in the direction of where I can find this information? Thanks... -Chris printenv from Konsole when you are logged in in graphics mode printenv from a console (logged in on runlevel 3) Check the settings of the DISPLAY variable Civileme Ummm... Well under the console perhaps better to printenv | less (blush). That fills more than a screen! The point is DISPLAY has a value in graphics mode and does NOT exist in console So if [ $DISPLAY ] then # DISPLAY is set and is a nonzero length string so do GUI stuff elif [ -z $DISPLAY ] # do the console stuf here (length of string is zero) else # do any other stuff here fi Civileme
Re: [expert] Bash Scripting
Necrotica wrote: I'm interested in learning a little about bash scripting. In particular, I'd like to learn how to tell if the user logging on is logging in under X or from a command prompt. Can anyone point me in the direction of where I can find this information? Thanks... -Chris Just see if $DISPLAY is set. (Sorry: I only know csh; there it's $?DISPLAY, but probably not the same for bash.) -- "Brian, the man from babble-on" [EMAIL PROTECTED] Brian T. Schellenberger http://www.babbleon.org Support http://www.eff.org. Support decss defendents. Support http://www.programming-freedom.org. Boycott amazon.com.
Re: [expert] BASH Shell games
Charles Curley wrote: Why is this failing? I must admit I didn't even look at your example beyond thinking that it was overkill ;) As far as I can see what you are looking for is cp -u sourcefile destination file which does exactly what you want with only one commnd! "man cp" for details. Hope this helps Lee -- Lee Willis [EMAIL PROTECTED] Application Developer PlusNet Technologies Ltd http://www.plus.net.uk
Re: [expert] BASH Shell games
On Wed, May 10, 2000 at 08:02:55PM -0500, Ron Johnson, Jr. wrote: - Charles Curley wrote: - [snip] - if [ /etc/fstab -nt $metatada/fstab ] || [ ! -f $metadata/fstab ] ; then - echo "Copying $metatada/fstab in from /etc." - cp /etc/fstab $metadata; - fi - [snip] - - $metatada - $metadata - ^^^ - - transcription error... Quite right, thank you all. One of these days I really should learn how to read. -- -- C^2 No windows were crashed in the making of this email. Looking for fine software and/or web pages? http://w3.trib.com/~ccurley
Re: [expert] BASH Shell games
On Thu, May 11, 2000 at 08:57:16AM +0100, Lee Willis wrote: - Charles Curley wrote: - - Why is this failing? - - I must admit I didn't even look at your example beyond thinking that it - was overkill ;) - - As far as I can see what you are looking for is - - cp -u sourcefile destination file - - which does exactly what you want with only one commnd! - - "man cp" for details. - - Hope this helps Yes, it does; thank you. -- -- C^2 No windows were crashed in the making of this email. Looking for fine software and/or web pages? http://w3.trib.com/~ccurley
Re: [expert] BASH Shell games
Charles Curley wrote: [snip] if [ /etc/fstab -nt $metatada/fstab ] || [ ! -f $metadata/fstab ] ; then echo "Copying $metatada/fstab in from /etc." cp /etc/fstab $metadata; fi [snip] $metatada $metadata ^^^ transcription error... Ron -- +--+ | Ron Johnson, Jr.Home: [EMAIL PROTECTED] | | Jefferson, LA USA WWW : [EMAIL PROTECTED] | | | | Most overused words: feel, cool/kewl, fun, myBlah.com| | Most underused word: think | +--+
Re: [expert] BASH Shell games
Well, at least in the version herein, you misspelled "metadata" in both the `echo` statement, and in the timestamp test. -Matt Stegman [EMAIL PROTECTED] On Wed, 10 May 2000, Charles Curley wrote: Why is this failing? I want to test two files, source and target. If the target does not exist, or the target does exist but is older than the source, I want to copy the source to the target. If the target does not exist, the file is copied. If the source is newer, no copy occurs. The code is: if [ /etc/fstab -nt $metatada/fstab ] || [ ! -f $metadata/fstab ] ; then echo "Copying $metatada/fstab in from /etc." cp /etc/fstab $metadata; fi ccurley@charlesc $ bash --version GNU bash, version 2.03.16(1)-release (i586-mandrake-linux-gnu) Copyright 1998 Free Software Foundation, Inc. -- -- C^2 No windows were crashed in the making of this email. Looking for fine software and/or web pages? http://w3.trib.com/~ccurley
[expert] BASH Shell games
Why is this failing? I want to test two files, source and target. If the target does not exist, or the target does exist but is older than the source, I want to copy the source to the target. If the target does not exist, the file is copied. If the source is newer, no copy occurs. The code is: if [ /etc/fstab -nt $metatada/fstab ] || [ ! -f $metadata/fstab ] ; then echo "Copying $metatada/fstab in from /etc." cp /etc/fstab $metadata; fi ccurley@charlesc $ bash --version GNU bash, version 2.03.16(1)-release (i586-mandrake-linux-gnu) Copyright 1998 Free Software Foundation, Inc. -- -- C^2 No windows were crashed in the making of this email. Looking for fine software and/or web pages? http://w3.trib.com/~ccurley
Re: [expert] bash script
Carl St-Jacques wrote: Hi, I need help... i have a file that i want to be copied in many folders. I tried to use a bash script with no success. The folders where the file have to be copied use a pattern based on a login name ex:(carlstj.macnt, lcl.macnt, etc...). The idea is to use this script to copy the file to the folders using a pattern matching /[a-zA-Z0-9].macnt/. thanks Carl St-Jacques for i in *.macnt; do cp file $i/. done -- Steve Philp Network Administrator Advance Packaging Corp. [EMAIL PROTECTED]