I'm parsing som .html files in bash. I read the in with:
while read line
do
echo $line
..do something...
done < $file
Now I've expierenced sth. real strange. Some lines in the files contain sth. like
Resolution…: 720 * 576
But bash gives me this:
Resolution…: 720 mysript.sh another_script.pl 576
Bash expands the * char to...
I have code matching:
if [ $LAST_MODIFIED -lt 3600 || ! -f "$i" ]; then
wget $WGET_OPTS $BASE$i
LAST_MODIFIED=`echo "\`date +%s\` - \`stat -c %Y $i\`" | bc`
if [ $LAST_MODIFIED -lt 500 ]; then
$FILES_MODIFIED++
fi
fi
$i is defined via
for i in `/bin/grep ".gz" index.html | awk -F\" '{print $2}'`
however, bas...
I have an interactive program that runs stdin and stdout.
I need to create wrapper that will send X to it's stdin, check that it prints Y and then
redirects wrapper's stdin and stdout to program's stdin and stdout just like program would be executed directly.
How to implement this ? X and Y can be hardcoded. Bash? Python?
Edit: I can't...
Is there any way I could use grep to ignore some files when searching something, something equivalent to svnignore or gitignore? I usually use something like this when searching source code.
grep -r something * | grep -v ignore_file1 | grep -v ignore_file2
Even if I could set up an alias to grep to ignore these files would be good.
...
Sorry I'm new to this sort of thing. I'm trying to write a bash script that uploads a file to a server. How can I achieve this? Is a bash script the right thing to use for this?
Solution:
I ended up using scp to copy the files securely.
scp <file to upload> <username>@<hostname>:<destination path>
I also set up public key authentica...
I am trying to create an ssh connection and do some things on the remote server from within the script.
However the terminal prompts me for a password, then opens the connection in the terminal window instead of the script. The commands don't get executed until I exit the connection.
How can ssh from within a bash script?
...
I want a way to kill a random process with a name (eg a random perl process).
What would be the best way of doing this?
I was thinkign of using something like this:
ps aux | grep PROCESS-NAME
to a file, then find a random line number, get the second column (process ID?) and kill that.
For my use it doesn't actually need to be a ...
Bash lets you complete commands names and names of files in the arguments with the TAB key.
But why not also common options to commands? Why not, even better, a completion system that tells you what an option does, too?
I heard of programmable completion.. but don't understand where it fits..
So my question is: is there a way to achiev...
I just want to match some text in a BASH script, i’v tried using sed, but I can’t seem to make it just output the match instead of replacing it with something.
echo -E "TestT100String" | sed 's/[0-9]+/dontReplace/g'
Which will output: TestTdontReplaceString
Which isn’t what I want, I want it to output: 100
Ideally I would want it to...
How do I check a int variable ($inputNo) to see if it’s 2 or more decimal digits long?
Example:
inputNo="5"
Should be changed to: 05
inputNo="102"
Should be left alone: 102
I thought about using wc and if statements, but wc -m doesn’t seems to give the actual characters passed into wc, as wc always seems to give +1 to the charact...
Hi all, I have a bash script that I am run to check to see if one of my programs has hung, and if it has kill it. The script works fine if ran from the command line, but if I schedule it with cron it does something very strange.
Basically the script (below) gets the PID of my program and gets its created date/time from its entry in the ...
I have this function, works fine, but I would like to rewrite it in bash. the problem is, I have too little knowledge of what's available in bash.
#!/usr/bin/python
def parse_svnversion(value):
"""split the output of svnversion into its three components
given a string that looks like the output of the command
svnversion, ...
Hello,
I'm attempting to write a bash routine that tests whether or not a user's input is the correct password to my certificate database.
Originally I imagined I'd first execute a benign certutil or pk12util operation on the certificate database that required a password. Then test the return code to see if it was successful.
However,...
hi
i have a .bash_favourites file which containes a list of my favourite commands.
I would like this be searchable via the normal bash history. ???
thanks
Ian
...
How to make locale aware uppercase operation?
Standard tr '[:lower:]' '[:upper:]' trick doesn't work:
=$ echo żółw | tr "[:lower:]" "[:upper:]"
żółW
(it should be ŻÓŁW)
I'd rather avoid having to run Perl or anything such heavy-weight.
...
How can I spawn a process after a delay in a shell script? I want a command to start 60 seconds after the script starts, but I want to keep running the rest of the script without waiting 60 seconds first. Here's the idea:
#!/bin/sh
# Echo A 60 seconds later, but without blocking the rest of the script
sleep 60 && echo "A"
echo "B"
echo...
I have a bash script that processes all of the files in a directory using a loop like
for i in *.txt
do
ops.....
done
There are thousands of files and they are always processed in alphanumerical order because of '*.txt' expansion.
Is there a simple way to random the order and still insure that I process all of the files only once?...
Hi,
I have written (tried to) this small bash script for searching through a range of directories.
#!/bin/bash
shopt -s nullglob
for file in [ac]*/blarg
do
echo $file
done
This script searches through directories starting with "a" through "c" for "blarg".
It only goes one level deep. How can I make it step through all directori...
Hi,
I need to replace the serials in my zone files, and I thought the easiest would be to use sed to change this. I have the following line to test.
@ IN SOA ns1.domain.com. webdev.domain.com. (
2006080401 ; serial
8H ; refresh
2H ; retry
1W ; expire
4h) ; minimum ttl
NS ns1.domain.com.
NS ns...
I do a fair bit of work at the command line. When I start my computer up on of the first things I do is open up a terminal window for mysql, and one for the Rails console and usually a third running mongrel. Setting it up every morning is a bit of a drag so I would like to script it. How can I open a terminal window, log into mysql, sele...