236 Posted Topics
Re: Hey there, This question has been answered on this board a few times, but the first thing you should look at is how you're calling your variables and iterating through them. For instance: [QUOTE]for $word in `cat filename1`; do echo $word[/QUOTE] should be [QUOTE]for word in `cat filename1`; do echo … | |
Re: Hey there, process/job - terms are sometimes misused or mixed up in regular reference to them, in everything from regular conversation to official text books. For awk, who, etc, you can run any process/job in the background without having to hit ctrl-Z by just starting them in the background, like: … | |
![]() | Re: Hey There, In bash (and similar shells) you can use read with the -n flag, like: read -n4 if you want to limit the variable input to 4 characters. If you want to just trim your variables, you can check the length of a variable by gettings the length value … |
![]() | Re: Hey there, How do you mean? Do you just want to read a file into a program or have the program read a file? Or something else. [CODE]while read x do echo $x done <input.thanks[/CODE] If you could clarify, that would be cool. Thanks, Mike |
![]() | Re: Hey there, This will tell you if your variable is text (a through z) - so your else would cover everything else :) [QUOTE][[ "$variable" == +([a-zA-Z]) ]] && echo "$variable is character"[/QUOTE] just put that in whatever if-else or other testing construct you want and you should be good … |
Re: Hey There, Your pretty much good, but I just use octals: so generic file = 644 110 100 100 umask 123 001 010 011 take the bitwise NOT of the umask (just flip the bits) 110 101 100 and the bitwise AND of that and your original perms (only columns … | |
Re: Hey There, If you just want to delete files that (I'm assuming) begin with a pound character and start with ifndef,define or endif, you could do it (not very generically in this example) by using sed: [QUOTE]$ sed '/^#[ifndef|define|endif]/d' FILENAME #if !defined(__lint) && !defined(_lint) XXXXXXXXXXXXXXXXXXXXXXXXX; #endif[/QUOTE] You can also be … | |
Re: Hey there, Does the line: open "/Volumes/ _Issues/$year/$month $monthname/$hotfolder/" not give you an error for "open"? Just curious. My bash's do. Some of the logic of the scripts function doesn't seem to be completed either, like the final move. Is this just part of the code? Or, possibly, a little … | |
Re: Hey there, Interesting. your execution statement looks like it should work. You can hedge your bets by enclosing the remote command in quotes: sh root@remoteServer "/var/spool/asterisk/voicemail/default/script" also, to double verify, add the hostname command in there: ssh root@remoteServer "hostname;/var/spool/asterisk/voicemail/default/script;hostname" You should the remote host name, your output and the remote … | |
Re: Hey there, It sounds like you want to change ethernet settings and reset your DNS. For DNS, the easiest way would be to create an additonal resolv.conf - /etc/resolv.conf.static or something like that - and backup your current resolv.conf and copy that one over it. For your ethernet address, you … | |
Re: Hey There, You pretty much had it. You just need to backslash the * (multiplication operator) and your script works perfectly :) [CODE]#!/bin/bash for (( i = 1 ; i <= 10; i++ )) do #J = 100 echo `expr 1000 \* $i` #java SortTester $num >> data.txt done[/CODE] [QUOTE]$ … | |
Re: Hey there, What have you got so far? Perhaps I can help you out by working with you on where your script is breaking down. Best wishes, Mike | |
Re: hey there, Glad I could help out on the last one. For this you can run: [CODE]$ awk 'BEGIN{sum1=$1;sum2=$2}{for (i=1;i<=NF;i++) {if ( i%2 ) {sum1 += $i; printf"%.2f ", $i}else {sum2 += $i; printf"%.2f ", $i}}}' FILE[/CODE] to get this output: [QUOTE]45.83 54.17 51.61 48.39 41.38 58.62 32.00 68.00 56.41 … | |
Re: Hey there, Just use the -p option to make dir and it should quit complaining about the directory already existing and do what you want. Also, if you don't need to make those dirs under multiple subdirs, you can remove the * character; that may cause it to give you … | |
Re: Hey there, I think definitely you'll see some differences in performance. Solaris' sh is the bourne shell and a lot of linux/bsd distro's just like sh to bash or another shell. The one thing I saw that jumped out at me was: if ["$daOslgCap" -gt "90%"] there may be 2 … | |
Re: Hey there, here's a quick, ugly-looking-but-easy-to-understand (I hope ;) bit of shell script. I didn't format the output exactly, but you should be able to do that simply by modifying the end of each line that seeds the newg and newh variable. The script is called c (below): Using your … | |
Re: Hey there, Hopefully this will help you out. It also avoids the illegal division by zero and just returns 0 in that condition. I put your values in a file called "awkpct" [QUOTE]host # cat awkpct 55 65 48 45 48 68 32 68 44 34 88 65 82 63 … | |
Re: Hey There, How are you formatting? locale -a should show you all the locales available, and you could use that to set your environment LC_ALL=[INSERT_YOUR_PREFERRED_LOCALE_FROM_local-a_ABOVE] locale charmap should set your formatting correctly. , Mike | |
Re: Hey there, To run them in the foreground, as Salem suggested, just remove the trailing ampersand on all your mdadm commands, so: mdadm --manage /dev/md0 --add /dev/sdb1 & becomes mdadm --manage /dev/md0 --add /dev/sdb1 and so forth. If you want to run all the mdadm commands at once in a … | |
Re: Hey There, check out this page for just about everythign you might need to know about bash arrays (at least, a lot of the basics ;) - This part addresses your issue, but the whole page is great! [url]http://tldp.org/LDP/abs/html/arrays.html[/url] [QUOTE]# Combine (append) two arrays into a third array. echo echo … | |
Re: Good deal - I was thinking you could recreate that pyramid doing a little less work, if you have "seq" to work with: [CODE]#!/bin/bash cnt=0 while [ $cnt -le 9 ] do echo `seq 0 $cnt` cnt=$((cnt+1)) done echo exit[/CODE] [QUOTE]host # ./program 0 0 1 0 1 2 0 … | |
Re: Hey there, Depending on what "mail" you're using (revisions, etc), you may be dealing with an issue that is caused by passing the -s "SUBJECT" argument to mail. If you have it on your system, you can change that line to read "mailx" instead of "mail" and it should work … | |
Re: Hey There, If there's any sort of delimiter at all between the fields (for instance, a colon), you can use awk's -F option, like: [QUOTE]awk -F":" '{print $1, $2, $3}'[/QUOTE] and so forth, Best wishes, Mike | |
Re: Hey there, If you want to do these en masse, you can either cd to the directory, or use a full path name and then apply that code generically to all the files in a for loop, while loop or using xargs, etc. That way your filename would be $x … | |
Re: Hey there, I would assume it's a representation of a generic compiled java binary. Best wishes, Mike | |
Re: I'm not sure this is in the right forum, but search your hard drive for the ftp.exe file. If it doesn't run automatically from your command prompt, the directory it's in might not be in your %PATH% variable. Best wishes, Mike | |
Re: Hey there, Did you want to do some calculation against the constant or just determine if a number is avogadro's number or not? If so, all you have to do is test whether or not the number equals the number (6.022 x 10 to the 23rd power). I'm probably missing … | |
Re: Hey There, Check out either uuencode/uudecode (for uuencoded attachments) or the freely available mpack/munpack binaries, for MIME attachments. Best wishes, Mike | |
Re: Yes, It would make more sense to just run it in a tmp script. The reason only the echo's work in the "while read" loop is that you're processing one line at a time, and not maintaining state between them, so the lines [QUOTE]aVar="Worked" echo $aVar[/QUOTE] are getting processed, but, … | |
Re: Hey there, The above comment is absolutely correct; just thought this might help a bit. If you want to print out the line numbers on your matches just print NR within awk, like [QUOTE]'{print NR}'[/QUOTE] or, since you want the whole line, too: [QUOTE]'{print NR,$0}'[/QUOTE] Format to taste ;) , … | |
Re: Hey There, Here's a cheap hack: [CODE]awk -F"[" '{print $3 " " $5 " " $9 " " $12}' LOGFILE|sed 's/^\([^\/]*\)\/[^\/]*\(\/[^]]*\)][^\"]*\"\([^\"]*\)\"[^\"]*\"\([^\"]*\)\".*/\3\|\1\|\2\|\4/'[/CODE] If you always get the double /'s on your directory path, just make this slight change: [CODE]awk -F"[" '{print $3 " " $5 " " $9 " " $12}' … | |
Re: Good work, I noticed that while I read your first post, but you found that read actually sets the variable for you. Good deal :) As for replaying, you can either loop by setting a trapping variable in a while loop (the cumbersome way) like: [CODE]goahead=0 while [ $goahead -ne … | |
Re: Hey there, this highly depends on the tool you decide to use. For simplicity, just use sed and type more than you need to for ease of understanding: [QUOTE]sed -n '/[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}/p' FILENAME[/QUOTE] You can also expand on that to pull more than one IP from a single line and tweak … | |
Re: There also seem to be a number of unnecessary backtick characters after a few then and else statements. That could be causing it. Best wishes, Mike | |
Re: What sort of backup did you do (ufsdump, netbackup, etc). You should just be able to restore based on a standard base directory and wildcards, like the find you did to get all the German files. If you let me know what you're using to backup/restore, I may be able … | |
Re: Hey There, I don't know if this is trivial - I couldn't find anything that specifically addressed it, but the easiest way I can think of would be to do a double run: bash -x script 2>&1|grep "^+" >>debugfile bash script 2 >>stderrfile and just sdiff them if you need … | |
Re: Hey there, You can post this in the C/C++ forum and someone there should know. Just send a reply asking to move your thread or kill this one and open a new one there. Best wishes, Mike | |
Re: Hey There, I'm assuming you meant the first line up to the { character (Let me know if I'm wrong). You could do this, keeping it simple: [QUOTE]grep test019|sed -n 's/.*\({\)/\1/p'[/QUOTE] Of course this very simple, using static variables from your example. Best wishes, Mike | |
Re: Hey there, Generate some random string, Use Gnu passwd. It has a --stdin option. Repeat 500 times, possibly in a while loop. Best wishes, Mike | |
Re: Hey There, Check this out. Basically, you just need to copy keys out to all your servers, so root can login without a password [url]http://linuxshellaccount.blogspot.com/2007/11/quick-guide-to-setting-up-ssh-keys.html[/url] There's another link on the site for how to run ssh in a loop if you have problems with that Best wishes, Mike | |
Re: Hey there, In simple terms, bash is a Unix/Linux shell and scripting in it is just like using the shell in a more sophisticated (or readable ;) way. Awk is a standalone utility that you can launch from bash. Bash can pretty much do anything (if you're creative) but awk … | |
Re: Looks pretty solid. Possibly try changing the variable ANSWER to something goofy, like BORG, just in case ANSWER is special (like REPLY). Best wishes, Mike | |
Re: Also, if it helps, your original redirect >$test was a redirect to value of the variable test, which may not have been defined, giving you the ambiguous redirect error. In most shell languages, use variable (when defining the variable) and $variable (when you want to access its value) Best wishes, … | |
Re: I'm dating myself, but my school's computer center had 2 or 3 TRS-80's ;) Eventually, we got a real computer class and they shelled out for some Commodore 2000's -- cutting edge :) , Mike | |
Re: You pretty much have your entire script right there, assuming you don't need to be any more creative, just add a #!/bin/bash line to the top and make it executable, etc, per the above post by John A Best wishes, Mike | |
Re: Hey There, Are you getting the value of $i during the sed command? I guess, more clearly, is that the first time? If that's the case, try defining $i outside of the sed command and the newline should go away when you echo your sed into the file. If I'm … | |
Re: Hey There, You're almost perfect there. The preferred way woud be for you to have a [QUOTE]P)[/QUOTE] and and [QUOTE]S)[/QUOTE] switch for each option, but you could do a range: [QUOTE][PS])[/QUOTE] instead. Your script now is looking for a literal "PS" argument. Hope that helps :) , Mike | |
Re: I don't think there's any product out there that will do this for you automatically, at least I couldn't find one. You'll probably have to do a straight-up port on your own. If you can post the script here (not too long and I'm not asking for you to reveal … | |
Re: Hey there, It may just be an issue with calling the variables. If you change [QUOTE]COL_GREEN='\E[32;01m'[/QUOTE] to [QUOTE]COL_GREEN="\033[32;1m"[/QUOTE] it might work better with the "echo -e" line. Hope that helps :) , Mike | |
Re: Hey There, Here's a link to a win32 tee emulator: [url]http://www.csc.calpoly.edu/~bfriesen/software/console.shtml[/url] Otherwise, if you can somehow manage to do this with robocopy, it's the only dos command I know that has a /TEE option Best of luck, Mike |
The End.