logo
IRC Archive / Freenode / #bash / 2010 / April / 21 / 5
koala_man
sami: no, use -name '*TID*'
hyper_ch
m4n: :)
sami
koala_man: ohh that easy
koala_man: That doesn't work as intended.
pgas
m4n: well yes, I was just showing an example of empty argument, a better example in the context would have been -o '', though I have no idea where the problem is and if there is one
argh too late
t3rm1n4l
is there a bash commonly used recipe available ?
Fatal
for cake?
sami
koala_man: nvm my bad
KiiK
how to answer it auto in bash.sh ?
Do you want to ignore this warning and proceed anyway?
To continue, enter "Yes"; to abort, enter "No":
koala_man
echo Yes | theCommandThatAsks
Superflaw|ay
(Action) would use a here string
mum-n-dad
At http://pastie.org/927513 - how do I incorporate the "retries" part with the now infinitely retrying "while ! git pull; do :; done" part?
Superflaw|ay
it's #bash
pgas
probably something like && ((retries--)); do
mum-n-dad
pgas: wow.. dude thank you so much
sami
Why wouldn't this work from within a script? TEST=`find * -maxdepth 1 -mtime +10 -name '*TID*' -exec ls {} \; | sed 's/"+TID+"//'`
pgas
use $( ) instead of ` `
sami
pgas: It still ignores the sed
hyper_ch
could it be that a process is finished yet for some reasons the data is not written entirely to disk yet?
pgas
sami: probably not, set -x is your friend
Riviera
sounds like you really should use wait
hyper_ch
wait doesn't work either
tried it, same result
Riviera
okay, sorry for the wild guess :)
hyper_ch
Riviera: it's ok... I think the problem is between the finishing of the process and the actual writing of data to the harddisk
since I then hash data on the harddisk it's of no use if the process is finished but data is still getting dumped onto the disk
mum-n-dad
pgas: yuu sure that works with zsh too?
im sorry for asking a zsh question in here though - but the guys in #zsh are as****es
pgas
no I'm not
seems to work here though:
% tries=2;while ! false && ((tries--));do echo tries;done
tries
mum-n-dad
sweet
you are a lifesaver dude
hyper_ch
hmmm, is there a way that I can specify a directory and list all open files within that directory?
Bushmills
hyper_ch: lsof should be helpful
Superflaw|ay
maybe lsof ?
hyper_ch
Bushmills: :)
Superflaw|ay
I'm interested in the flags, if you find them all :p
zarck
or fuser
hyper_ch
Superflaw|ay: just read through lsof :)
Bushmills
hyper_ch: it wasn't me
hyper_ch
damn :( it just doesn't want to work :(
sami
As i understand it find -mtime +10 would be 10 days.
twkm
modulo granularity, yes.
mum-n-dad
pgas: It keeps retrying infinitely it seems
trash
zsh
pgas
mum-n-dad: ah, well the retries test should come first
mum-n-dad
yeah sorry about that trash
hyper_ch
I finally got it :)
Bushmills
+d /path/dir works for me
Mohan
what does '(:h)' this one do in the above pastie?
for folder in $PWD/**/.git(:h); do
pgas
ask in #zsh
Mohan
oh its not bash, I didn't notice it.
Bushmills
sami, not quite. it'd be 11 days, where 1 day ago means "at least 24h ago"
actually, +0 does not find files < 24 h
kbrandt
What is the proper way to kill jobs all on a singal (and any children of those jobs?)
Oh nevermind, I have it I think, had an eval in there
sami
Bushmills: Ok
Thanks
zxd_
what does set -e do
I forgot
ok
got it
hever
Hi. I'm checking the occourence of a string in stdin using a loop in a loop. It works but I think there are better solutions, do you have any suggestions? http://pastebin.com/qPibyK11
realubot
I got some help here beofre, but I didn't manage to get the code working using the tip so I'll ask you once again.
twkm
hever: [[
SuperFlo
(Action) was thinking of something that ugly : egrep -q "(t1|t2)" && exit
pgas
hever: if would use awk...or maybe grep is enough?
hever
its a variable amount of strings I'm checking...
twkm, I use [[
Bushmills
you could test for t[1,2]
twkm
then why do you need two loops?
realubot
I have a text file conatining only one signel line that's very long. The line has got special characters that seperate some different parts of the line, like <seperator>. Then I want to "save" different parts of the line into different variables, like the text between first and second tag into var1 and the text between second and third tag into var2 and so on. After having like 6 variables I'll store the text between
pgas
hever: you can still use grep, with one pattern per line in a variable
hever
Bushmills, the Exeption will be some strings t1,2 are just examples.
Bushmills
so was my reply :D
realubot
This is what that the text file looks like: <tag>this is some text<tag>this is also some text<tag>this too<tag>
hever
twkm, because I've a variable amount of exeptions I'm going to check...
Perhaps this code is good enough....
pgas
IFS=$'\n'; if grep -q "${array[*]}";then echo match;fi
realubot
Then I want to create a variable contining the text between 1st and 2nd tag into var1 and the text between 2nd tag and 3rd tag into var2 and so on...
After like tag 6 or 7 I will start over agian and create var1 out of the 7 to 8 tag, var2 out of the 8-9 tag etc.
lhunath
if (IFS=$'\n'; grep -q ..)
hever
whats IFS?
SuperFlo
internal field separator
realubot
I'm looking for a way to grep the text between like the n:th and (n+1):th <tag>.
pgas
realubot: use an xml/html parser
realubot
pgas: The tags are all the same, like <tag>, there is no special tags, just <tag> between the text parts of the line.
pgas: Not <title>, <content> or something, just <tag>.
pgas
realubot: paste an example of your input
realubot
Isn't it possible to like remove all but the text between tag n and n+1 using like sed, wehere I add n++ at the end of the loop, going through the loop over and over agian?
sn18
realubot: read it into array?
hever
lhunath, that does not work ;)
realubot
pgas: Well, it looks like this: <tag>Some kind of text<tag>more text<tag>hey ho let's go<tag>one more text string<tag>
pgas: It's one single line and I get it from zenity --list --editable --column1="Title"...
pgas
# arr=( foo bar baz); echo foo | if ( IFS=$'\n';grep -q "${arr[*]}");then echo hever: works here ;fi
evalbot
pgas: hever: works here
realubot
Zenity outputs all in a editable list by having the --separator="<tag>" to put <tag> between the content of each column. I can't set speciela seperators for each tag.
pgas
realubot: you can perhaps use something like awk -F '<[^>]*>' '{print $2}'
lhunath
hever: that "works" just fine, and I was merely improving upon pgas' suggestion; not sure what it is *you* are after exactly.
hever
aah you have to pipe it to if ...
pgas
hever: well not really, grep reads from stdin
echo foo | was just a way to write something on stdin
lhunath
!io > hever
greybot
hever: Data and File Processing: http://mywiki.wooledge.org/BashGuide/InputAndOutput
realubot
pgas: Yeah, I'm not that familiar in using awk. Maybe I can use something like sed 's/<tag>/ \n /g' > input.txt then loop every line using while read line; do echo "$line" done < input.txt
twkm
i suggest not using bash, and write the entire thing in awk or perl or ruby or ...
hever
lhunath, http://pastebin.com/gnB2GFmd
realubot
twkm: It will take me too much time cause I'm not used to Perl or Ruby.
pgas
hever: what is your script supposed to do? print all the lines up to the one matching one of the pattern?
realubot
Why do you not suggest using bash to parse text between tags? I mean, bah is very powerfull and will somehow manage to do this kind of job, am I wrong?
hever
this example yes, the realone is an email log reporter
pgas
realubot: yes, but it's not made for this kind of job, the result will be slow and it will involve more works
hever: well, I would write an awk script
realubot
pgas: Ok.
pgas
or perl or ...
hever
just use the two loops ;)
pgas
what I've just said to realubot applies to you too
JoshDreamland
Hi, is there a way to move the contents of all the directories in a directory to a new directory, without moving the directory names themselves?
For example, a/ contains folder b/ and c/. A separate folder, d/, is elsewhere. Can I move a/b/* and a/c/* to d/ without moving b/ and c/ and without knowing their names?
Copying is fine, rather. Not necessarily move.
I just need a copy of the contents of all subfolders to be moved to a new folder.
spixx|work
cp -r ?
cp -r /folder/with/subfolders/
sn18
JoshDreamland: using find or globstar in bash 4
JoshDreamland
sn18: then piping their output to cp?
Titan8990
JoshDreamland: possibly: find /path -type f -exec bash -c 'cp "$1" newdir/' -- '{}' \;
JoshDreamland
Titan8990: Thanks, I'll give that one a try
Titan8990: Worked great. Thanks much!
Titan8990
JoshDreamland: np
pgas
if you use \; you can do -exec cp -- {} newdir \;
Stalafin
hey! i have a question about the printf command: if i want to print the vars FOO and BAR, would printf "%s\t%s" ${FOO} ${BAR} work? or is there something wrong with my syntax?
twkm
i would quote the parameter expansions, otherwise it seems fine.
tjg
Hi, hopefully you can help me... I have a bash script where I launch a daemon in the background, then get its PID using $!. But when I launch it with a different user (su --command "<cmd> &" <user>), I don't know how to get the PID. How should I approach this?
Stalafin
twkm: quote the parameter expansion?
twkm: as in "${FOO}" ?
zimmermanc
# cat "${FOO}"
evalbot
zimmermanc: cat: : No such file or directory
zimmermanc
doh
Fatal
Stalafin: "$FOO" works fine (${FOO} == $FOO, "${FOO}" == "$FOO", the {} adds nothing)
tjg
Hmm, I'm thinking I can put the command in its own bash script, which I call with a different user... And within that script, write $! to a file, so my outer script can find it.
pgas
that or sh -c 'cmd & echo $!'
SuperFlo
tjg: that's usually what daemons do, they have a pid file
tjg
pgas: Ah cool, I'll try that out!
mum-n-dad
pgas: is this: while ! git pull && sleep 5 && ((retries--)); do :; done
the same as: git pull && break || sleep 5?
i mean which would be preferred..
tjg
SuperFlo: Yeah... This shell script (I didn't write it) is in /etc/init.d, and then writes the pid file after launching the command in the background... I'm not a sophisticated bash programmer, so I have no idea whether this is good form.
DrMax_
is there a way, within a script, to determine if the script was launched from the prompt or "source"d ?
mum-n-dad
At http://pastie.org/927926 - will "while ! git pull; do break; done" stop the script if "git pull" fails, or will the loop keep on running?
mum-n-dad
I.e. I get "fatal: The remote end hung up unexpectedly"
Kniht
DrMax_: if you figure out what you asked, though, I could use that too :)
DrMax_
Kniht : I have a... let's call that a legacy script... that expects to be sourced rather than invoked directly
except that I do not have the invoker
Kniht
mum-n-dad: 'break' exits from the while loop, 'break 2' would exit the for loop, 'exit' will exit the script
sn18
DrMax_:BASH_LINENO?
noesc
I would need some help in parsing a file. I've got a sh*tload of files ~6,5k where ALOT of them are duplicates (with different filenames), and I want to remove all duplicates. I've calculated md5sums for all files and saved to a normal textfile. How would I continue from here?
pgas
use an already existing script?
DrMax_
sn18 : it's undefined unless from a script ?
hmm ok let's try this
pgas
DrMax_: is it supposed to be sourced from a login shell? or from another script?
noesc: shelldorado has such a script, there is an "fdupes" out there
mum-n-dad
pgas: is while ! git pull && ((5)); do the same as doing retries=5 and then while ! git pull && ((retries--)); do?
noesc
pgas, I'll check it
thanks
DrMax_
pgas : the intended use is probably to be sourced from another script, which doesn't exist anymore. You have to invoke source script.sh for it to work properly
which is cumbersome
sn18
mum-n-dad: no
pgas
DrMax_: so you source it from another script?
DrMax_
or fix the source-dependent parts
mum-n-dad
sn18: How do I do it then?
DrMax_
hmm ok
pgas
? oh well..
mum-n-dad
pgas: Could you give me a hand?
ebi
Does anyone know how to get bash completion for the history search commands like !:tab tab
mum-n-dad
pgas: At http://pastie.org/927926 - this script should: if "git pull" fails, retry it 5 times (but sleep 5 seconds prior to each attempt) - and if that too fails, stop the whole script. Am I doing it right?
andy_t_roo
does command || exit 1; terminate the script if command fails?
sn18
mum-n-dad: while loop will continue till git pull succeeds
mum-n-dad
andy_t_roo: I don't know, I'm using command || break;
sn18
mum-n-dad: you dont need || break
mum-n-dad
sn18: I only want it to run 5 times
sn18: Is that possible?
sn18
mum-n-dad: retries=5 ; while ! git pull && ((retries--)); do
mum-n-dad
sn18: I must have retries=5?
there's no way around that?
Bushmills
no. you can also have 10
then you'd do ((retries-=2))
mum-n-dad
What I mean is, do I really need that variable thing
can't i just incorporate the 5 retries in the while loop itself?
Bushmills
for i in {1..5}; do ... ; done
mum-n-dad
ok ill keep the variable thing :)
sn18
sleep 5 && :