Hello-
I am a newbie in Bash and I am doing some string manipulation.
I have the following file among other files in my directory:
jdk-6u20-solaris-i586.sh
I am doing the following to get jdk-6u20 in my script:
myvar=`ls -la | awk '{print $9}' | egrep "i586" | cut -c1-8`
echo $myvar
but now I want to convert jdk-6u20 to jdk1.6.0_2...
I'm trying to setup an automated "build" server for my rails projects using Hudson CI. SO far it's able to run specs and do metrics on the code but I have 2 different projects dependent on 2 different versions of ruby. So i'm trying to use RVM to run multiple copies of ruby then switch back and forth in a pre-build step.
I found a coup...
Here is a problem:
In my bash scripts I want to source several file with some checks, so I have:
if [ -r foo ] ; then
source foo
else
logger -t $0 -p crit "unable to source foo"
exit 1
fi
if [ -r bar ] ; then
source bar
else
logger -t $0 -p crit "unable to source bar"
exit 1
fi
# ... etc ...
Naively I tried to create ...
I am writing a little install script for some software. All it does is unpack a target tar, and then i want to permanently set some environment variables - principally the location of the unpacked libs and updating $PATH. Do I need to programmatically edit the .bashrc file, adding the appropriate entries to the end for example, or is the...
This is the script I currently have-
#!/bin/bash
if["$#" == "2" OR who | grep ":0" == ""]
export DISPLAY=:0
xset dpms force on
mplayer -fs $1.mp4
fi
It doesn't work.
Thanks for your help.
...
Hello,
I have a bash script that I want to change all occurrences of jdk1.5.0_14 with jdk1.6.0_20 in a file
I have the following piece of code :
#!/bin/bash
myvar="jdk1.6.0_20"
sed "s/jdk1.*/$myvar/g" answer_file.1 > answer_file.2
However I have the following information in answer_file.1 (pasting the relevant part):
JDKSelection.d...
I have a file that contains filenames like this:
my_cool_file.xxx
my_cool_file2.xxx
my_cool_file3.xxx
I have a folder that has:
some_file.xxx
some_file2.xxx
some_file3.xxx
I would like to have a bash script to take one line from the filename file and rename one file in the folder.
Is there a way to do this?
...
I'm trying to create a cronjob to back up my database every night before something catastrophic happens. It looks like this command should meet my needs:
0 3 * * * pg_dump dbname | gzip > ~/backup/db/$(date +%Y-%m-%d).psql.gz
Except after running that, it expects me to type in a password. I can't do that if I run it from cron. How can...
Hi,
I have a fairly simple bash shell scripting problem.
I want to sed a piece of text and then assign the result of the sed to a variable.
#!/bin/bash
MOD_DATE=echo $(date) | sed 's/\ /_/g'
echo $MOD_DATE // should show date with spaces replaced with underscores.
I have tried the above and it doesn't work. Can anyone point out what...
I am playing with using flock, a bash command for file locks to prevent two different instances of the code from running more than once.
I am using this testing code:
( ( flock -x 200 ; sleep 10 ; echo "original finished" ; ) 200>./test.lock ) &
( sleep 2 ; ( flock -x -w 2 200 ; echo "a finished" ) 200>./test.lock ) &
I am running 2...
Hi
I've done a bit of searching on here and on other sites, it seems this question has been asked a few times, but rather than giving the actual code, people only give the theory.
I wish to create a reliable way to get the progress of a transcode. It seems the best way is to use the total frames of the source file and then get the curr...
For example, say I have string like:
duck duck duck duck goose goose goose dog
And I want it to be as sparsely populated as possible, say in this case
duck goose duck goose dog duck goose duck
What sort of algorithm would you recommend? Snippets of code or general pointers would be useful, languages welcome Python, C++ and extra k...
Anybody know if it is possible that when making a tar + gzip through 'tar c ...' command if the relative paths will be ignored upon expanding.
e.g.
tar cvf test.tgz foo ../../files/bar
and then expanding the test.tgz with:
tar xvf test.tgz
gives a dir containing:
foo files/bar
i want the dir to contain the files
foo bar
is thi...
I have a file of 256MB. I'd like to retrieve a random amount of data from this file and copy it to another file.
Is there a way to do this in bash or some other way?
G-Man
Edit: choose a random number between 1 and 256 then copy that number of mb from one file to another.
...
hi,
I'm trying to strip the version out of a package name using only Bash. I have one solution but I don't think that's the best one available, so I'd like to know if there's a better way to do it. by better I mean cleaner, easier to understand.
suppose I have the string "my-program-1.0" and I want only "my-program". my current solutio...
Say I want a certain block of bash script execute only if it is between 8 am (8:00) and 5 pm (17:00), and do nothing otherwise. The script is running continuously
So far I am using date command.
How to use it compare it current time within the range?
Thanks
...
Is there more elegant way of doing lazy evaluation than the following:
pattern='$x and $y'
x=1
y=2
eval "echo $pattern"
results:
1 and 2
It works but eval "echo ..." just feels sloppy and may be insecure in some way. Is there a better way to do this in Bash?
...
Hi,
I'm trying to print arguments passed to a ./configure script. Calling 'echo' on $BASH_ARGV will just print the last set of arguments. For example if I run:
./configure --enable-foo --enable-bar
echo $BASH_ARGV will print only "--enable-bar"
How do I print all the arguments? Thanks!
...
I've got a text file, and wish to extract every above the !--- comment ---! into a new file, not based line numbers (but checking for the comment), How would I do this?
test123
bob
ted
mouse
qwerty
!--- comment ---!
123456
098786
...
I wrote a bash-script to check if a process is running. It doesn't work since the ps command always returns exit code 1. When I run the ps command from the command-line, the $? is correctly set, but within the script it is always 1. Any idea?
#!/bin/bash
SERVICE=$1
ps -a | grep -v grep | grep $1 > /dev/null
result=$?
echo "exit code: $...