[newbie] Script for iptables
How do I create a script for iptables? ---Dennis "[EMAIL PROTECTED]"Registered Linux User #382526
Re: [newbie] Script for iptables
On Monday 07 March 2005 11:09, Dennis wrote: How do I create a script for iptables? You can google for one. But is not the sort of thing a newbie needs to do. There are perfectly good front ends for iptables such as the shorewall firewall built into Mandrake that makes writing your own iptables scripts unnecessary. derek -- www.jennings.homelinux.net http://twiki.mdklinuxfaq.org Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com Join the Club : http://www.mandrakeclub.com
Re: [newbie] Script for iptables
On Mon, 2005-03-07 at 19:09 +0800, Dennis wrote: How do I create a script for iptables? --- Dennis [EMAIL PROTECTED] Registered Linux User #382526 Add a contrib source then do urpmi ipkungfu. Thats an awesome iptables script. Thats what I think anyways. Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com Join the Club : http://www.mandrakeclub.com
Re: [newbie] Script for burning DVD images
On February 11, 2005 00:41, David G Stevenson wrote: ... Anyway, I took a few minutes and turned it into a reusable script. I've attached it here for anyone who might find themselves in a similar situation. Maybe someday this missing feature will get added to K3b. In the meantime, enjoy. Thanks, You're welcome. A very minor contribution back to the community. DVDDEV=/dev/hdc Youl need to change this to suit as hdc is probably most used for the first hard disk on the first IDE channel of most default systems. Yeah, there's a note in the comments within the script that this needs to be set for whatever drive your burner is. That's what mine is, just because it's the first device on the second ide bus. If anyone knows a way to make this more generic, I'd be happy to apply the change. /usr/bin/growisofs -Z ${DVDDEV}=${1} \ -use-the-force-luke=notray -use-the-force-luke=tty \ -use-the-force-luke=tracksize:2268160 \ -use-the-force-luke=dao:2268160 \ -dvd-compat -speed=4 2268160 = this is the real tracksize in bytes, so this would need to be altered for each burn. Yeah, I was curious about those numbers, since the options are undocumented (at least in the man page). I thought they might need to change for each disk image. But I burnt three different images each of a different size, and they all seemed to work. So it's not clear to me when these numbers would need to change. Have a look at the URL posted yesterday... On Thursday 10 Feb 2005 11:03, [EMAIL PROTECTED] wrote: http://www.troubleshooters.com/linux/coasterless_dvd.htm Added to the TWiki on http://mandrake.vmlinuz.ca/bin/view/Main/DvD Anne HTH. I didn't notice this link previously. Sometimes I don't get a chance to read my email for a couple of days, then have to very quickly scan several hundred messages, so I probably scanned right over it. I'll check it out. I added another line to the script, making it version 0.2: eject ${DVDDEV} This makes it eject the disk when burning is done, providing a convenient feedback that it's done, similar to K3b (though this seems to be broken for DVDs in K3b; it only works for me with CDs). Thanks for the feedback. -- Ron ronhd at users dot sourceforge dot net Opinions expressed here are all mine. As you know, necessity is the mother of invention. I don't know who the father is. Remorse, I guess. - Red Green Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com Join the Club : http://www.mandrakeclub.com
[newbie] Script for burning DVD images
I ran into an interesting problem today. I have some wedding DVDs that family friends keep asking for copies of. I had been using K3b's Copy DVD tool. But I realized I could shave about 20 minutes off the time for each disk if I saved the image and reused it, instead of rereading the originals each time. I saved the images by selecting the Only create image option. But when I went to burn copies, I ran into trouble. I had assumed that K3b would create an ISO image, and that I could just do a Burn DVD Image from it. I was worried when I saw the .img file extension that K3b used, rather than the conventional .iso. I tried anyway, but the disk was unusable. Then I tried New Data DVD Project, added the image file, but same result. I couldn't find anything in the K3b help, or on google. So I went back to copying from the original. But after a successful copy, I was able to grab the actual command executed to burn the image from the Debugging Output of K3b (I wish all GUI tools would give you the command line equivalent like this, very educational). Turns out it's the growisofs command, with a number of undocumented -use-the-force-luke options. Anyway, I took a few minutes and turned it into a reusable script. I've attached it here for anyone who might find themselves in a similar situation. Maybe someday this missing feature will get added to K3b. In the meantime, enjoy. -- Ron ronhd at users dot sourceforge dot net Opinions expressed here are all mine. As you know, necessity is the mother of invention. I don't know who the father is. Remorse, I guess. - Red Green burn_dvd_image.sh Description: application/shellscript Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com Join the Club : http://www.mandrakeclub.com
Re: [newbie] Script for burning DVD images
Ron Hunter-Duvar wrote: I ran into an interesting problem today. I have some wedding DVDs that family friends keep asking for copies of. I had been using K3b's Copy DVD tool. But I realized I could shave about 20 minutes off the time for each disk if I saved the image and reused it, instead of rereading the originals each time. I saved the images by selecting the Only create image option. snip Anyway, I took a few minutes and turned it into a reusable script. I've attached it here for anyone who might find themselves in a similar situation. Maybe someday this missing feature will get added to K3b. In the meantime, enjoy. Thanks, DVDDEV=/dev/hdc Youl need to change this to suit as hdc is probably most used for the first hard disk on the first IDE channel of most default systems. /usr/bin/growisofs -Z ${DVDDEV}=${1} \ -use-the-force-luke=notray -use-the-force-luke=tty \ -use-the-force-luke=tracksize:2268160 \ -use-the-force-luke=dao:2268160 \ -dvd-compat -speed=4 2268160 = this is the real tracksize in bytes, so this would need to be altered for each burn. Have a look at the URL posted yesterday... On Thursday 10 Feb 2005 11:03, [EMAIL PROTECTED] wrote: http://www.troubleshooters.com/linux/coasterless_dvd.htm Added to the TWiki on http://mandrake.vmlinuz.ca/bin/view/Main/DvD Anne HTH. -- Thanks, David Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com Join the Club : http://www.mandrakeclub.com
[newbie] newbie script help
Greetings and Happy NewYear, I would like to write a script to accomplish a task, and then run it at regular intervals (I'll start another thread for that). The thing is I know zero about programming and in process of learning. I have a stand-alone firewall (mdk9.1) with no X installed, and a wireless card and my access to the internet is from a access point else where. I would like to get the info from /proc/net/wireless (on the firewall) like below. ~$ date cat /proc/net/wireless So after a while I came up with something like this below #! /bin/bash #Take wireless link readings from /proc/net/wireless and output to #file wireless_stat { date; cat /proc/net/wireless; } wireless_stat -- That seems to give me what I want and I like to set it up to run every 5 minutes with cron.hourly (next thread). Now every 24 hours I would like to take the file wireless_stat and tar/gzip it up and start a new one like below. ~$ tar -c -z -f wireless_stat1.tar wireless_stat then run ~$ rm -f wireless_stat; touch wireless_stat; How would I write a script that it would increment the the archived files like logrotate does? For instance. ~/tmp$ ll -rw-rw-r--1 mike mike 3084 Jan 4 08:44 wireless_stat -rw-rw-r--1 mike mike 359 Jan 3 19:33 wireless_stat1.tar Then 24 hours later this. ~/tmp$ ll -rw-rw-r--1 mike mike 3084 Jan 4 08:44 wireless_stat -rw-rw-r--1 mike mike 359 Jan 3 19:33 wireless_stat1.tar -rw-rw-r--1 mike mike 359 Jan 3 19:33 wireless_stat2.tar This where I'm getting stuck would this be a loop? or a statement? Would it be a (if, while, for,)? I have a book to help, but I'm afraid my brain is stuck in a (loop) of not understanding and can not progress... :-) Any guidance would appreciated, Mike Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [newbie] newbie script help
Hi Mike, Your script to 'logrotate' the files could look like this: #!/bin/sh filetest() { if [ -f wireless_stat$1.tar ] ; then mv -f wireless_stat$1.tar wireless_stat$2.tar fi } cd /directory where your files are filetest 4 5 filetest 3 4 filetest 2 3 filetest 1 2 The filetest function takes 2 arguments, being the oldest and one newer file (you can expand this check to as many as you like, but if you want to keep things around forever, this would not be the best way to do it). To run this thing, put it somewhere and let root's cron take care of things. Paul On 01/04/2004 05:05 PM, mike wrote: Greetings and Happy NewYear, I would like to write a script to accomplish a task, and then run it at regular intervals (I'll start another thread for that). The thing is I know zero about programming and in process of learning. Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [newbie] newbie script help
Paul wrote: Hi Mike, Your script to 'logrotate' the files could look like this: #!/bin/sh filetest() { if [ -f wireless_stat$1.tar ] ; then mv -f wireless_stat$1.tar wireless_stat$2.tar fi } cd /directory where your files are filetest 4 5 filetest 3 4 filetest 2 3 filetest 1 2 The filetest function takes 2 arguments, being the oldest and one newer file (you can expand this check to as many as you like, but if you want to keep things around forever, this would not be the best way to do it). To run this thing, put it somewhere and let root's cron take care of things. Paul Thanks Paul! I think I understand the function is to take the oldest which is the first argument if it exists rename it to the second argument. So it cd's to my file directory and sees if wireless_stat3.tar it would filetest 3 4 (rename file3.tar to file4.tar) and 2 to 3, 1 to 2. Yes, I was wondering how to keep it from running forever. I see now by what you have in your script. Now to put it all together could I do something like this? - #! /bin/bash tar -c -z -f wireless_stat1.tar wireless_stat something() { if [ -f wireless_stat1.tar ] ; then rm -f wireless_stat; touch wireless_stat; fi } filetest() { if [ -f wireless_stat$1.tar ] ; then mv -f wireless_stat$1.tar wireless_stat$2.tar fi } cd /home/mike/tmp filetest 4 5 filetest 3 4 filetest 2 3 filetest 1 2 - Mike Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [newbie] newbie script help
On 01/04/2004 07:30 PM, mike wrote: I think I understand the function is to take the oldest which is the first argument if it exists rename it to the second argument. Yup. So it cd's to my file directory and sees if wireless_stat3.tar it would filetest 3 4 (rename file3.tar to file4.tar) and 2 to 3, 1 to 2. Yes, I was wondering how to keep it from running forever. I see now by what you have in your script. Good! :) Now to put it all together could I do something like this? I'd suggest this: #--start script #! /bin/bash filetest() { if [ -f wireless_stat$1.tar ] ; then mv -f wireless_stat$1.tar wireless_stat$2.tar fi } cd /home/mike/tmp filetest 4 5 filetest 3 4 filetest 2 3 filetest 1 2 tar -c -z -f wireless_stat1.tar wireless_stat if [ -f wireless_stat1.tar ] ; then rm -f wireless_stat; touch wireless_stat; fi #--end script First you define the function (it is only defined, not run), then you cd to $HOME/tmp. Then cycle the backup tar-files. That way you move the existing backups out of the way, preserving the old #1 as #2 and getting rid of old #5 in the process. And then you build the new stat1.tar after which you create a clean stat-file. Do you see the logic in this? I hope this is clear enough. Good luck, Paul Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [newbie] newbie script help
Paul wrote: On 01/04/2004 07:30 PM, mike wrote: I think I understand the function is to take the oldest which is the first argument if it exists rename it to the second argument. Yup. So it cd's to my file directory and sees if wireless_stat3.tar it would filetest 3 4 (rename file3.tar to file4.tar) and 2 to 3, 1 to 2. Yes, I was wondering how to keep it from running forever. I see now by what you have in your script. Good! :) Now to put it all together could I do something like this? I'd suggest this: #--start script #! /bin/bash filetest() { if [ -f wireless_stat$1.tar ] ; then mv -f wireless_stat$1.tar wireless_stat$2.tar fi } cd /home/mike/tmp filetest 4 5 filetest 3 4 filetest 2 3 filetest 1 2 tar -c -z -f wireless_stat1.tar wireless_stat if [ -f wireless_stat1.tar ] ; then rm -f wireless_stat; touch wireless_stat; fi #--end script First you define the function (it is only defined, not run), then you cd to $HOME/tmp. Then cycle the backup tar-files. That way you move the existing backups out of the way, preserving the old #1 as #2 and getting rid of old #5 in the process. And then you build the new stat1.tar after which you create a clean stat-file. Do you see the logic in this? I believe I do now, I had things reversed, I should of taking care of moving my backups to make room for the new ones before deleting the first file, else lose data! Also I noticed that I was trying to make a function out a if statement ( something() ) which was not necessary, probably not right either *grin* And the #--startscript, #--endsript to know when the script begins and ends. I should also add some comments about what its doing for my sake. I hope this is clear enough. Yes, again thanks Paul! You walked me right through it, easier than I thought it would be. I'll probably post back on the running the cron part but, I'll research it a bit more before I panic. :-) Mike Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Cron (was Re: [newbie] newbie script help)
On 01/04/2004 08:32 PM, mike wrote: I'll probably post back on the running the cron part but, I'll research it a bit more before I panic. :-) Your friends there will be: man crontab man 5 crontab and perhaps also man cron It is not difficult, just something you need to get used to. su to root, and type 'crontab -e' to edit the crontab file. But first read up on how to define things. And make sure you know how to handle vi... Paul Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: Cron (was Re: [newbie] newbie script help)
Paul wrote: On 01/04/2004 08:32 PM, mike wrote: I'll probably post back on the running the cron part but, I'll research it a bit more before I panic. :-) Your friends there will be: man crontab man 5 crontab and perhaps also man cron It is not difficult, just something you need to get used to. su to root, and type 'crontab -e' to edit the crontab file. But first read up on how to define things. And make sure you know how to handle vi... For those who think life is too short for vi, there is also kcron. Sir Robin -- Certitude is possible for those who only own one encyclopedia. - Robert Anton Wilson Robin Turner IDMYO Bilkent Univeritesi Ankara 06533 Turkey www.bilkent.edu.tr/~robin Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: Cron (was Re: [newbie] newbie script help)
On Sunday 04 January 2004 22:00, robin wrote: For those who think life is too short for vi, there is also kcron. and Webmin Anne -- Registered Linux User No.293302 Have you visited http://twiki.mdklinuxfaq.org yet? Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
[newbie] Script in the init dir
I can't seem to be able to run a script when my machine boots up... I copied it in /etc/init.d/ though, and I can run it from the shell (/etc/init.d/myscript start), but it's not launched at boot time. Am I missing something here? Thanks, -- Alexandre Aractingi [EMAIL PROTECTED] Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [newbie] Script in the init dir
On Fri, 2003-12-05 at 07:50, Alexandre Aractingi wrote: I can't seem to be able to run a script when my machine boots up... I copied it in /etc/init.d/ though, and I can run it from the shell (/etc/init.d/myscript start), but it's not launched at boot time. Am I missing something here? Thanks, Startup scripts has to follow some rules. For example, it is mandatory to have a coupe of lines hinting default runlevels and priority at start up and shutdown. Something like: # chkconfig: 2345 90 20 # description: A comment to describe what this script does. You have to handle at least the cases to start and stop the service you are dealing with this script. OTOH, if you are trying to start a program, not a service, you better use rc.local. HTH -- Adolfo A. Bello B. [EMAIL PROTECTED] Make your posts more effective. Learn how at http://mandrake.vmlinuz.ca/bin/view/Main/MandrakeMailingListEtiquette Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [newbie] Script in the init dir
Le ven 05/12/2003 à 13:12, Adolfo Bello a écrit : Startup scripts has to follow some rules. For example, it is mandatory to have a coupe of lines hinting default runlevels and priority at start up and shutdown. Something like: # chkconfig: 2345 90 20 # description: A comment to describe what this script does. You have to handle at least the cases to start and stop the service you are dealing with this script. OTOH, if you are trying to start a program, not a service, you better use rc.local. Thanks for your explanations! I'll do that! -- Alexandre Aractingi [EMAIL PROTECTED] Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [newbie] Script in the init dir
I thought that the start and stop priority were provided by the /etc/rcx.d/ symlink names, i.e. S03iptables S10network starts iptables before network. Are those two lines relly needed by rc script, or by some other configuration utility? thanks, raffaele [EMAIL PROTECTED] wrote: On Fri, 2003-12-05 at 07:50, Alexandre Aractingi wrote: I can't seem to be able to run a script when my machine boots up... I copied it in /etc/init.d/ though, and I can run it from the shell (/etc/init.d/myscript start), but it's not launched at boot time. Am I missing something here? Thanks, Startup scripts has to follow some rules. For example, it is mandatory to have a coupe of lines hinting default runlevels and priority at start up and shutdown. Something like: # chkconfig: 2345 90 20 # description: A comment to describe what this script does. You have to handle at least the cases to start and stop the service you are dealing with this script. OTOH, if you are trying to start a program, not a service, you better use rc.local. HTH 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: [newbie] Script in the init dir
On Fri, 2003-12-05 at 09:27, Raffaele Belardi wrote: I thought that the start and stop priority were provided by the /etc/rcx.d/ symlink names, i.e. S03iptables S10network starts iptables before network. Are those two lines relly needed by rc script, or by some other configuration utility? thanks, raffaele chkconfig uses that line (the # chkconfig one) to create the symlinks. For more information, take a look at the RUNLEVEL FILES section in man chkconfg. Saludos, -- Adolfo A. Bello B. [EMAIL PROTECTED] Make your posts more effective. Learn how at http://mandrake.vmlinuz.ca/bin/view/Main/MandrakeMailingListEtiquette Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [newbie] Script in the init dir
On Sat, 06 Dec 2003 00:50, Alexandre Aractingi wrote: I can't seem to be able to run a script when my machine boots up... I copied it in /etc/init.d/ though, and I can run it from the shell (/etc/init.d/myscript start), but it's not launched at boot time. Am I missing something here? Or you can use ksysv... Copy your script to /etc/rc.d/init.d and make permissions 700 (rwx--) owned by root. Open ksysv from a terminal as root and choose linux as your OS, then Mandrake Linux. You can now drag and drop your script into the desired run levels. More info in the KDE docs. Sharrea -- Help Microsoft stamp out piracy - give Linux to a friend today Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [newbie] Script to change multiple filenames
* Todd Slater [EMAIL PROTECTED] [01-11-2003 23:55]: On Sat, 11 Jan 2003 17:22:43 -0800 You don't have to use the ls command, this will work for files with spaces in the name and also accounts for differing case: for image in /path/to/directory/*.[Jj][Pp][Gg] do FCNT=`printf %02d $CNT` echo $image $FCNT-$NAME$EXT CNT=$(($CNT+1)) done Now the problem becomes mv. When specifying a name that contains a space, mv interprets it as multiple files as well. A backslash needs to be added somehow so that mv knows it's a single file. ab\ cd.jpg == 01-pic.jpg -- Regards, Matt Florido Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [newbie] Script to change multiple filenames
On Sun, 12 Jan 2003 09:26:13 -0800 Matt Florido [EMAIL PROTECTED] wrote: * Todd Slater [EMAIL PROTECTED] [01-11-2003 23:55]: On Sat, 11 Jan 2003 17:22:43 -0800 You don't have to use the ls command, this will work for files with spaces in the name and also accounts for differing case: for image in /path/to/directory/*.[Jj][Pp][Gg] do FCNT=`printf %02d $CNT` echo $image $FCNT-$NAME$EXT CNT=$(($CNT+1)) done Now the problem becomes mv. When specifying a name that contains a space, mv interprets it as multiple files as well. A backslash needs to be added somehow so that mv knows it's a single file. ab\ cd.jpg == 01-pic.jpg Are you using bash or another shell? On my system (using bash) it works fine. Be sure you leave the quotes around $image. Todd Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [newbie] Script to change multiple filenames
* Todd Slater [EMAIL PROTECTED] [01-12-2003 12:58]: On Sun, 12 Jan 2003 09:26:13 -0800 Are you using bash or another shell? On my system (using bash) it works fine. Be sure you leave the quotes around $image. Hi Todd, I am using bash. You're correct. For some reason, I removed the quotes when I add mv. mv $image test/$FCNT-$NAME$EXT changed it to: mv $image test/$FCNT-$NAME$EXT and now all is well!! Thanks again! -- Regards, Matt Florido Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [newbie] Script to change multiple filenames
On Saturday 11 Jan 2003 4:46 am, Todd Slater wrote: On Fri, 10 Jan 2003 20:31:05 -0800 Matt Florido [EMAIL PROTECTED] wrote: I was wondering if someone could assist me in creating a shell script that will take the contents of a directory and rename them a certain way. For example - 4 files in a directory: a.jpg ab.jpg abc.jpg abcd.jpg Renamed as: 1-pic.jpg 2-pic.jpg 3-pic.jpg 4-pic.jpg So it takes the contents of the directory regardless of the current filename, and renames them in an incrementing format. ((N+1) + -something.jpg) Change the variables to your taste. The printf in the script will write a leading 0 in the number--that's always a gotcha when the order is important. If you have more than 99 images, you can change the 2 to a 3 and you'll get 001, 002 etc. Test it out first, then change echo to mv, remove the quotes around the expression after that, take out the == of course. HTH, Todd #!/bin/bash EXT=.jpg NAME=pic CNT=1 for image in `ls /path/to/directory | sort` do FCNT=`printf %02d $CNT` echo $image == $FCNT-$NAME$EXT CNT=$(($CNT+1)) done exit Just wondering - sorting numbered files is always problematic. Could you pad to 3 digits, sort of if length-of numberstring 3, the for 3-length-of-numberstring print 0 then continue as before? I haven't yet learned syntax for bash programming, but I guess you will understand what I mean. Anne Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [newbie] Script to change multiple filenames
On Sat, 11 Jan 2003 13:42:48 + Anne Wilson [EMAIL PROTECTED] wrote: On Saturday 11 Jan 2003 4:46 am, Todd Slater wrote: On Fri, 10 Jan 2003 20:31:05 -0800 Matt Florido [EMAIL PROTECTED] wrote: I was wondering if someone could assist me in creating a shell script that will take the contents of a directory and rename them a certain way. For example - 4 files in a directory: a.jpg ab.jpg abc.jpg abcd.jpg Renamed as: 1-pic.jpg 2-pic.jpg 3-pic.jpg 4-pic.jpg So it takes the contents of the directory regardless of the current filename, and renames them in an incrementing format. ((N+1) + -something.jpg) Change the variables to your taste. The printf in the script will write a leading 0 in the number--that's always a gotcha when the order is important. If you have more than 99 images, you can change the 2 to a 3 and you'll get 001, 002 etc. Test it out first, then change echo to mv, remove the quotes around the expression after that, take out the == of course. HTH, Todd #!/bin/bash EXT=.jpg NAME=pic CNT=1 for image in `ls /path/to/directory | sort` do FCNT=`printf %02d $CNT` echo $image == $FCNT-$NAME$EXT CNT=$(($CNT+1)) done exit Just wondering - sorting numbered files is always problematic. Could you pad to 3 digits, sort of if length-of numberstring 3, the for 3-length-of-numberstring print 0 then continue as before? I haven't yet learned syntax for bash programming, but I guess you will understand what I mean. Anne If I understand your question correctly, that's what this line does: FCNT=`printf %02d $CNT` (That forces it to be 2 digits, with a leading 0 if necessary. Changing the 2 to a 3 will force 3 digits with leading 0's.) $CNT is the number variable that gets incremented by 1 for each file the script processes. $FCNT formats that number to be 2 digits. Todd Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [newbie] Script to change multiple filenames
On Saturday 11 Jan 2003 2:10 pm, Todd Slater wrote: On Sat, 11 Jan 2003 13:42:48 + Anne Wilson [EMAIL PROTECTED] wrote: On Saturday 11 Jan 2003 4:46 am, Todd Slater wrote: On Fri, 10 Jan 2003 20:31:05 -0800 Matt Florido [EMAIL PROTECTED] wrote: I was wondering if someone could assist me in creating a shell script that will take the contents of a directory and rename them a certain way. For example - 4 files in a directory: a.jpg ab.jpg abc.jpg abcd.jpg Renamed as: 1-pic.jpg 2-pic.jpg 3-pic.jpg 4-pic.jpg So it takes the contents of the directory regardless of the current filename, and renames them in an incrementing format. ((N+1) + -something.jpg) Change the variables to your taste. The printf in the script will write a leading 0 in the number--that's always a gotcha when the order is important. If you have more than 99 images, you can change the 2 to a 3 and you'll get 001, 002 etc. Test it out first, then change echo to mv, remove the quotes around the expression after that, take out the == of course. HTH, Todd #!/bin/bash EXT=.jpg NAME=pic CNT=1 for image in `ls /path/to/directory | sort` do FCNT=`printf %02d $CNT` echo $image == $FCNT-$NAME$EXT CNT=$(($CNT+1)) done exit Just wondering - sorting numbered files is always problematic. Could you pad to 3 digits, sort of if length-of numberstring 3, the for 3-length-of-numberstring print 0 then continue as before? I haven't yet learned syntax for bash programming, but I guess you will understand what I mean. Anne If I understand your question correctly, that's what this line does: FCNT=`printf %02d $CNT` (That forces it to be 2 digits, with a leading 0 if necessary. Changing the 2 to a 3 will force 3 digits with leading 0's.) $CNT is the number variable that gets incremented by 1 for each file the script processes. $FCNT formats that number to be 2 digits. That sounds really useful. I said I only half-understood it :) Thanks Anne Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [newbie] Script to change multiple filenames
On Sat, 11 Jan 2003 17:22:43 -0800 Matt Florido [EMAIL PROTECTED] wrote: * Todd Slater [EMAIL PROTECTED] [01-10-2003 23:46]: #!/bin/bash EXT=.jpg NAME=pic CNT=1 for image in `ls /path/to/directory | sort` do FCNT=`printf %02d $CNT` echo $image == $FCNT-$NAME$EXT CNT=$(($CNT+1)) done exit Todd, That works well except for files with spaces. A file named ab cd.jpg is interpreted as two files. ab and cd.jpg Thanks again! Matt, You don't have to use the ls command, this will work for files with spaces in the name and also accounts for differing case: for image in /path/to/directory/*.[Jj][Pp][Gg] do FCNT=`printf %02d $CNT` echo $image $FCNT-$NAME$EXT CNT=$(($CNT+1)) done Todd Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
[newbie] Script to change multiple filenames
I was wondering if someone could assist me in creating a shell script that will take the contents of a directory and rename them a certain way. For example - 4 files in a directory: a.jpg ab.jpg abc.jpg abcd.jpg Renamed as: 1-pic.jpg 2-pic.jpg 3-pic.jpg 4-pic.jpg So it takes the contents of the directory regardless of the current filename, and renames them in an incrementing format. ((N+1) + -something.jpg) -- Regards, Matt Florido Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [newbie] Script to change multiple filenames
On Fri, 10 Jan 2003 20:31:05 -0800 Matt Florido [EMAIL PROTECTED] wrote: I was wondering if someone could assist me in creating a shell script that will take the contents of a directory and rename them a certain way. For example - 4 files in a directory: a.jpg ab.jpg abc.jpg abcd.jpg Renamed as: 1-pic.jpg 2-pic.jpg 3-pic.jpg 4-pic.jpg So it takes the contents of the directory regardless of the current filename, and renames them in an incrementing format. ((N+1) + -something.jpg) Change the variables to your taste. The printf in the script will write a leading 0 in the number--that's always a gotcha when the order is important. If you have more than 99 images, you can change the 2 to a 3 and you'll get 001, 002 etc. Test it out first, then change echo to mv, remove the quotes around the expression after that, take out the == of course. HTH, Todd #!/bin/bash EXT=.jpg NAME=pic CNT=1 for image in `ls /path/to/directory | sort` do FCNT=`printf %02d $CNT` echo $image == $FCNT-$NAME$EXT CNT=$(($CNT+1)) done exit Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [newbie] script help
MG wrote: Hey Mark, I was just using ./HW as in: [mike@avatar mike]$ ./HW What I gathered was if the script was in a directory, that was in my PATH, I could just use the name of the script instead of the whole path. I looked in my /home/mike/.bash_profile file and it said: [mike@avatar mike]$ cat .bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin Perhaps /home/mike/bin is not in the path of PATH=$PATH:$HOME/bin ? Mike Hi Mike, Thats correct. When you're in your home dir and you're calling an executable file you'll need to include the path to that executable in order for it to be executed. Your other option would be to place the file somewhere in your path such as /usr/bin or /usr/local/bin. -- Mark --- I had 49 days uptime until my wife brought the servers down when she ran the vacuum cleaner. --- Paid for by Penguins against modern appliances(R) Linux User Since 1996 Powered by Mandrake Linux 8.2 9.0 Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [newbie] script help
MG wrote: Hi all, This question is not really Mandrake specific although I am using Mandrake8.2 (and like it alot!)...anyways trying to learn the bash shell. I wrote a small script (the Hello World script) and named it HW. I did a chmod 755 to it, so all could read and execute it. I made a /bin directoy in my home directoy and put the script there. But my problem is I can only execute it when I am in the directoy of the script. I have a permission problem(I think), but cant seem to find it. Any help would be appreciated. Here is where scipt is at: /home/mike/bin/practice_script/ [mike@avatar practice_script]$ ls -al total 12 drwxr-xr-x2 mike mike 4096 Dec 28 09:51 ./ drwxr-xr-x3 mike mike 4096 Dec 28 21:24 ../ -rwxr-xr-x1 mike mike 52 Dec 28 09:51 HW* -rw-r--r--1 mike mike0 Dec 28 09:49 HW~ If I execute the script any where but /practice_script/ I get this [mike@avatar mike]$ ./HW bash: ./HW: No such file or directory Thanks, Mike Mike, When you call it from anywhere else except the directory where it's located how are you calling it? for instance...if yo're in /home/mike and you want to call the script you would call it this way: bin/practice_script/HW [enter] Is this how you're doing it? Mark Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [newbie] script help
Hey Mark, I was just using ./HW as in: [mike@avatar mike]$ ./HW What I gathered was if the script was in a directory, that was in my PATH, I could just use the name of the script instead of the whole path. I looked in my /home/mike/.bash_profile file and it said: [mike@avatar mike]$ cat .bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin Perhaps /home/mike/bin is not in the path of PATH=$PATH:$HOME/bin ? Mike On Wednesday 01 January 2003 03:36 pm, you wrote: MG wrote: Hi all, This question is not really Mandrake specific although I am using Mandrake8.2 (and like it alot!)...anyways trying to learn the bash shell. I wrote a small script (the Hello World script) and named it HW. I did a chmod 755 to it, so all could read and execute it. I made a /bin directoy in my home directoy and put the script there. But my problem is I can only execute it when I am in the directoy of the script. I have a permission problem(I think), but cant seem to find it. Any help would be appreciated. Here is where scipt is at: /home/mike/bin/practice_script/ [mike@avatar practice_script]$ ls -al total 12 drwxr-xr-x2 mike mike 4096 Dec 28 09:51 ./ drwxr-xr-x3 mike mike 4096 Dec 28 21:24 ../ -rwxr-xr-x1 mike mike 52 Dec 28 09:51 HW* -rw-r--r--1 mike mike0 Dec 28 09:49 HW~ If I execute the script any where but /practice_script/ I get this [mike@avatar mike]$ ./HW bash: ./HW: No such file or directory Thanks, Mike Mike, When you call it from anywhere else except the directory where it's located how are you calling it? for instance...if yo're in /home/mike and you want to call the script you would call it this way: bin/practice_script/HW [enter] Is this how you're doing it? Mark Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [newbie] script help
Here's the rub, by type ./HW you are telling bash to run it in the current directory. Also, path's are NOT recursive, so when you put it inside a second folder inside the ~/bin directory, it will not see it. Put the HW script directly into your ~/bin directory, then then type just HW (NOT ./HW) Chuck On Wed, 2003-01-01 at 17:10, MG wrote: Hey Mark, I was just using ./HW as in: [mike@avatar mike]$ ./HW What I gathered was if the script was in a directory, that was in my PATH, I could just use the name of the script instead of the whole path. I looked in my /home/mike/.bash_profile file and it said: [mike@avatar mike]$ cat .bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin Perhaps /home/mike/bin is not in the path of PATH=$PATH:$HOME/bin ? Mike On Wednesday 01 January 2003 03:36 pm, you wrote: MG wrote: Hi all, This question is not really Mandrake specific although I am using Mandrake8.2 (and like it alot!)...anyways trying to learn the bash shell. I wrote a small script (the Hello World script) and named it HW. I did a chmod 755 to it, so all could read and execute it. I made a /bin directoy in my home directoy and put the script there. But my problem is I can only execute it when I am in the directoy of the script. I have a permission problem(I think), but cant seem to find it. Any help would be appreciated. Here is where scipt is at: /home/mike/bin/practice_script/ [mike@avatar practice_script]$ ls -al total 12 drwxr-xr-x2 mike mike 4096 Dec 28 09:51 ./ drwxr-xr-x3 mike mike 4096 Dec 28 21:24 ../ -rwxr-xr-x1 mike mike 52 Dec 28 09:51 HW* -rw-r--r--1 mike mike0 Dec 28 09:49 HW~ If I execute the script any where but /practice_script/ I get this [mike@avatar mike]$ ./HW bash: ./HW: No such file or directory Thanks, Mike Mike, When you call it from anywhere else except the directory where it's located how are you calling it? for instance...if yo're in /home/mike and you want to call the script you would call it this way: bin/practice_script/HW [enter] Is this how you're doing it? Mark 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: [newbie] script help
Thanks Chuck! It works, I believe I understand now, thats why I got a No such file or directory it could not see it in the folder I made. again appreciate the guidance. Mike On Wednesday 01 January 2003 04:54 pm, you wrote: Here's the rub, by type ./HW you are telling bash to run it in the current directory. Also, path's are NOT recursive, so when you put it inside a second folder inside the ~/bin directory, it will not see it. Put the HW script directly into your ~/bin directory, then then type just HW (NOT ./HW) Chuck On Wed, 2003-01-01 at 17:10, MG wrote: Hey Mark, I was just using ./HW as in: [mike@avatar mike]$ ./HW What I gathered was if the script was in a directory, that was in my PATH, I could just use the name of the script instead of the whole path. I looked in my /home/mike/.bash_profile file and it said: [mike@avatar mike]$ cat .bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin Perhaps /home/mike/bin is not in the path of PATH=$PATH:$HOME/bin ? Mike On Wednesday 01 January 2003 03:36 pm, you wrote: MG wrote: Hi all, This question is not really Mandrake specific although I am using Mandrake8.2 (and like it alot!)...anyways trying to learn the bash shell. I wrote a small script (the Hello World script) and named it HW. I did a chmod 755 to it, so all could read and execute it. I made a /bin directoy in my home directoy and put the script there. But my problem is I can only execute it when I am in the directoy of the script. I have a permission problem(I think), but cant seem to find it. Any help would be appreciated. Here is where scipt is at: /home/mike/bin/practice_script/ [mike@avatar practice_script]$ ls -al total 12 drwxr-xr-x2 mike mike 4096 Dec 28 09:51 ./ drwxr-xr-x3 mike mike 4096 Dec 28 21:24 ../ -rwxr-xr-x1 mike mike 52 Dec 28 09:51 HW* -rw-r--r--1 mike mike0 Dec 28 09:49 HW~ If I execute the script any where but /practice_script/ I get this [mike@avatar mike]$ ./HW bash: ./HW: No such file or directory Thanks, Mike Mike, When you call it from anywhere else except the directory where it's located how are you calling it? for instance...if yo're in /home/mike and you want to call the script you would call it this way: bin/practice_script/HW [enter] Is this how you're doing it? Mark 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
[newbie] Script
I need this script to do the following things, in order to start some clients palace servers It simply stops after the first user what the problem #!/bin/sh su angeleyez ; /home/angeleyez/palaceserver/bin/start-palace ; exitsu digitalfantasy ; /home/digitalfantasy/palaceserver/bin/start-palace ; exitsu j323k41j4 ; /home/j323k41j4/palaceserver/bin/start-palace ; exitsu redbaron ; /home/redbaron/palaceserver/bin/start-palace ; logoutsu staticfx ; /home/staticfx/palaceserver/bin/start-palace ; exitsu zach ; /home/zach/palaceserver/bin/start-palace ; exit Jesse AngellKorrupt.com Supportaim: korruptDOTcomemail: [EMAIL PROTECTED]
[newbie] Script for Log Extraction
Hello, I have a text file that looks like this on Linux: --- ^M 01:23:00 ^M 23 Oct. 2001 Bobo Permitted ^M I need to filter records based a name (Bobo), but also need the line that is two lines above. For example, I can do: # more Log_October_2001 | grep Bobo This will give me 22 records for example, anyone know how I can also see the line that also has the time stamp? i.e., two lines above, so I can get the following output: 01:23:00 23 Oct. 2001 Bobo Permitted Many thanks!! Robert Want to buy your Pack or Services from MandrakeSoft? Go to http://www.mandrakestore.com
Re: [newbie] script or program for sharing internet..
It was Sat, 30 Jun 2001 13:04:20 -0500 when Eduardo Dominguez wrote: Anyone knows about such a thing ? I am trying to share my ppp connection and it has been a PITA. I read a bunch of how-to's and still nothing. Look at http://mandrakeuser.org and look for line sharing there. It is pretty simple once you got it. Paul -- I prefer rogues to imbeciles, because they sometimes take a rest. -Alexandre Dumas (fils) http://nlpagan.net - Registered Linux User 174403 Linux Mandrake 8.0 - Sylpheed 0.4.99 ** http://www.care2.com - when you care **
[newbie] script help
Hi to all, If I have a file with the following data: listen 010:atm1.7530 listen 010:atm120.7080 listen 010:nac1.7506 listen 010:ist1.7508 listen 010:tar.7501 listen 010:nacpos.7510 How I can extract of the second column since ':' to '.' example: 010:atm1.7530 atm1 010:atm120.7080 atm120 I think with the command awk I can do that.. but right now I don't have any idea Can anybody help me? Thanks in advance winmail.dat
Re: [newbie] script help
On Thursday 05 April 2001 15:52, you wrote: Hi to all, If I have a file with the following data: listen 010:atm1.7530 listen 010:atm120.7080 listen 010:nac1.7506 listen 010:ist1.7508 listen 010:tar.7501 listen 010:nacpos.7510 How I can extract of the second column since ':' to '.' example: 010:atm1.7530 atm1 010:atm120.7080 atm120 I think with the command awk I can do that.. but right now I don't have any idea Can anybody help me? Thanks in advance cat datafilename | gawk -F: '{ print $2 }' | gawk -F. '{ print $1 }' outfile then it will have the contents in outfile that you desire. Civileme Yeh, one-line filters are common for something that would be a hairy VB job.
Re: [newbie] script help
listen 010:atm1.7530 listen 010:atm120.7080 [...] How I can extract of the second column since ':' to '.' example: 010:atm1.7530 atm1 010:atm120.7080 atm120 cat datafilename | gawk -F: '{ print $2 }' | gawk -F. '{ print $1 }' outfile or $ cut -f 2 -d : datafile|cut -f 1 -d . outfile Probably uses fewer cpu cycles if the datafile is big. MB
Re: [newbie] Script errors during kernel upgrade
I don't think you can regenerate that file. It is not necessary for the stock kernels to boot and is just something Mandrake put it in there. Try creating just an empty file with the name the rpm wants. module-info should be a link to module-infokernel version just like vmlinuz was a link to vmlinuzkernel version. So the command would be something like "touch module-info-linux-2.2.14-mdk" Hope this helps John -- Original Message -- From: Claudio [EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED] Date: Sat, 15 Jul 2000 04:32:42 -0300 (ART) Hi, I am trying to upgrade my 2.2.14 kernel to 2.2.16 but with problems. During the process the rpm reports that couln't find vmlinuz and stops. The link of vmlinuz and system.map, in /boot, are broke. These links I correct. The problem is with the module-info points to old version and I couldn't find the its new version. How can I generate or get this new version of module-info? Thanks, Claudio H. O YAHOO! GEOCITIES CHEGOU AO BRASIL! Crie sua home page com tudo em português - http://br.geocities.com
[newbie] Script errors during kernel upgrade
Hi, I am trying to upgrade my 2.2.14 kernel to 2.2.16 but with problems. During the process the rpm reports that couln't find vmlinuz and stops. The link of vmlinuz and system.map, in /boot, are broke. These links I correct. The problem is with the module-info points to old version and I couldn't find the its new version. How can I generate or get this new version of module-info? Thanks, Claudio H. O YAHOO! GEOCITIES CHEGOU AO BRASIL! Crie sua home page com tudo em português - http://br.geocities.com
[newbie] script: host available??
How can I check within a script if a specific computer is reachable within my LAN? I need something like: if hostname_is_online then xxx else yyy fi Thanks! Regards, Claus. -- Atzenbeck. Data structures design http://www.atzenbeck.de You can now buy more gates with less specifications than at any other time in history. -- Kenneth Parker
Re: [newbie] script: host available??
On Tue, 25 Apr 2000, flupke wrote: I think a "ping -c 1 hostname /dev/null 21" should do it. Thanks! This is exactly what I was looking for! Regards, Claus. -- Atzenbeck. Data structures design http://www.atzenbeck.de Never test for an error condition you don't know how to handle. -- Steinbach