Hi,
I'm very new in programming. The following task looks very simple but I don't know how to do it. Appreciate if anyone can give me some guidance.
I'm using Linux OS. I would like to create a CLI program and let the user run it in shell terminal. I plan to use Bash shell script to create this program, but C++ or Perl should be ok too...
This might be a noob question, but I need help. I screwed up my terminal by trying to alter my path variable using the following command:
$ sudo nano .profile
Before I did that, if I were to type:
$ echo $PATH
I would get: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
When I opened .profile in nano it told me that the fil...
He all,
i have a problem with my bash script.
That's my code:
#!/bin/bash
java -jar my_app.jar
echo "The present working directory is `pwd`"
If i exec it by ./script_name it work, but if i double click on it don't work, i got this error:
"Unable to access jarfile my_app.jar".
Then the pwd output is different !!!
My OS is MacOSX but i...
I have a file have lots of string tags like </usr/share/some_pattern>, all they have in common is they all begin with a < and end with a >, how can write a bash script to remove all these tags(including the strings inside)?
...
In a bash script, if I have a number that represents a time, in the form hhmmss (or hmmss), what is the best way of subtracting 10 minutes?
ie, 90000 -> 85000
...
This command has an empty output.
su user -c "ABC=abc;echo $ABC"
Any idea, how can I define a variable in the input command?
...
I have a folder with a bunch of files. I need to delete all the files created before July 1st. How do I do that in a bash script?
...
I wrote a number of bash scripts that greatly simplify the routine, but very tedious, file manipulation that my group does.
Unfortunately, most in my group cannot open a terminal, let alone run scripts with complex arguments.
Is there a way to nicely package a bash script into an executable (that accepts arguments) that runs nicely on ...
I use md5sum to generate a hash value for a file.
But i only need to receive the hash value, not the file name.
md5=`md5sum ${my_iso_file}`
echo ${md5}
3abb17b66815bc7946cefe727737d295 ./iso/somefile.iso
How can i 'strip' the file name and only remain the value ?
...
I have a part of my script that does this:
Removes everything in directory
Force syncs from perforce that directory
copies files from another directory to said directory, of which there are some conflicts that the source control prevent from being overwritten (which is expectable and what I want)
Before I would have just this:
...
c...
I have a problem.
I want to run a ruby script from another ruby script and capture it's output information while letting it output to the screen too.
runner
#!/usr/bin/env ruby
print "Enter your password: "
password = gets.chomp
puts "Here is your password: #{password}"
The script file that I run:
start.rb
output = `runner`
puts o...
Hi,
I'm currently having a already a bash script with a few thousand lines which sends various queries MySQL to generate applicable output for munin.
Up until now the results were simply numbers which weren't a problem, but now I'm facing a challenge to work with a more complex query in the form of:
$ echo "SELECT id, name FROM type O...
I'd like to use the time command in a bash script to calculate the elapsed time of the script and write that to a log file. I only need the real time, not the user and sys. Also need it in a decent format. e.g 00:00:00:00 (not like the standard output). I appreciate any advice.
...
I have this user crontab (accessed via the command crontab -e):
# m h dom mon dow command
*/3 * * * * sh /home/FRAPS/Desktop/cronCheck.sh
The script cronCheck.sh looks like that:
#!/bin/sh
SERVICE='Script'
if ps ax | grep -v grep | grep -i "$SERVICE" > /dev/null
then
echo "######## $SERVICE service running, everythin...
how can I execute a shell command in the background from within a bash script, if the command is in a string?
For example:
#!/bin/bash
cmd="nohup mycommand";
other_cmd="nohup othercommand";
"$cmd &";
"$othercmd &";
this does not work -- how can I do this?
...
In Bash, what is the simplest way to test if an array contains a certain value?
EDIT: with help from the answers and the comments, after some testing, I came up with this:
function contains() {
local n=$#
local value=${!n}
for ((i=1;i < $#;i++)) {
if [ "${!i}" == "${value}" ]; then
echo "y"
...
Hi All,
I've used regex's in sed before and used a bit of awk, but am unsure of the exact syntax I need here...
I want to do something like:
sed -i 's/restartfreq\([\s]\)*\([0-9]\)*/restartfreq\1$((\2/2))/2/g' \
my_file.conf
where the second match is divided by 2 and then put back in the inline edit.
I've read though that sed ca...
What are the benefits of using FileUtils methods http://ruby-doc.org/core/classes/FileUtils.html than the equivalent Bash commands?
...
My bash script produces a log file. Now i'd like to implement some log file rotation. Let's say the first time it's called somelog.log, the next time it's renamed to somelog.log.1 and the new log file somelog.log.The third time the new log is somelog.log again, but somelog.log.1 is renamed to somelog.log.2 and the old somelog.log to some...
I use this piece of code in my bash script to read a file containing several hex strings, do some substitution and then write it to a new file. It takes about 30 minutes for about 300 Mb.I'm wondering if this can be done faster ?
sed 's,[0-9A-Z]\{2\},\\\\x&,g' ${in_file} | while read line; do
printf "%b" ${line} >> ${out_file}
printf ...