I'd like to save the current directory where the each command was issued alongside the command in the history. In order not to mess things up, I was thinking about adding the current directory as a comment at the end of the line. An example might help:
$ cd /usr/local/wherever
$ grep timmy accounts.txt
I'd like bash to save the last...
I have a badly behaving process (launched via a user command) which keeps dying at erratic intervals, and I need it to stay alive till I manually kill it. Here is my straight, but probably stupid solution:
#!/bin/bash
if [ -z $1 ]
then
echo "Usage: /s98ize.sh <process name>"
exit
fi
#start of the 'polling' loop
while [ 1 ]
do
pgre...
Here is what I tried but failed:
[root@file nutch-0.9]# cp -f urls-resume /nosuchdirectory/hi.txt
cp: cannot create regular file `/nosuchdirectory/hi.txt': No such file or directory
[root@file nutch-0.9]#
besides,any way to make ">" work that way,say to create a directory when need?
[root@file nutch-0.9]# echo test > /nosuchtest/hi.t...
Is there any way to debug a bash script? E.g something that prints a sort of execution log like "calling line 1", "calling line 2" etc.
...
Possible Duplicate:
Linux: Prevent a background process from being stopped after closing SSH client
I have a program that takes a lot of time to finish.
It is running as root over ssh.
I want it to continue to run after I logout,is this possible and how would I achieve this?
...
What scripts do you regularly use to improve your productivity?
Over the last year I have been trying to use bash scripts and commands to improve my productivity as a developer (Web and applications). Here is a list of a few simple ones that I use:
Make files lower case:
for i in *.txt; do mv "$i" "`echo $i| tr [A-Z] [a-z]`"; done
...
My bash init script (~/.profile) contains important initializations, but whenever I use shell-command or compile in emacs, that init file is not read, and without those initialization my bash commands in emacs will fail :( How do I force emacs to execute my init file for the shell that it's using for shell-command?
Clarification: I'm no...
Let's say I have a script like the following:
useless.sh
echo "This Is Error" 1>&2
echo "This Is Output"
And I have another shell script:
alsoUseless.sh
./useless.sh | sed 's/Output/Useless/'
I want to capture "This Is Error", or any other stderr from useless.sh, into a variable.
Let's call it ERROR.
Notice that I am using stdo...
I want to get the filename (without extension) and the extension separately.
The best solution I found so far is:
NAME=`echo "$FILE" | cut -d'.' -f1`
EXTENSION=`echo "$FILE" | cut -d'.' -f2`
This is bad because it doesn't work if the filename contains multiple "." characters. If let's say I have a.b.js it will consider a and b.js, in...
I'm working with a utility (unison, but that's not the point) that accepts parameters like:
$ unison -path path1 -path path2 -path path3
I would like to write a sh script that I could run like this:
$ myscript path1 path2 path3
I'm hoping for a Posix compliant solution, but bash-specific would also be good.
I'm guessing it should ...
Hi,
We've had these for a lot of other languages. The one for C/C++ was quite popular, so was the equivalent for Python. I thought one for BASH would be interesting too.
...
The way to iterate over a range in bash is
for i in {0..10}; do echo $i; done
What would be the syntax for iterating over the sequence with a step? Say, I would like to get only even number in the above example.
...
I have a little Bash script which suspends the computer after a given number of minutes. However, I'd like to extend it to tell me what the time will be when it will be suspended, so I can get a rough idea of how long time I have left so to speak.
#!/bin/sh
let SECS=$1*60
echo "Sleeping for" $1 "minutes, which is" $SECS "seconds."
slee...
Is there anyway to pipe the output of a command which lists a bunch of numbers (each number in a separate line) and initialize a bash array with those numbers ?
Details:
This lists 3 changelist numbers which have been submitted in the following date range. The output is then piped to "cut" to filter it further to get just the changeli...
To redirect stderr to stdout we use 2 > &1. Why is it not just 2 > 1? why & is needed?
...
For example, I might want to:
tail -f logfile | grep org.springframework | <command to remove first N characters>
I was thinking that 'tr' might have the ability to do this but I'm not sure.
Thanks in advance stackoverflow geniuses!
--
LES
...
I am using 'tail -f' to follow a log file as it's updated:
tail -f logfile
I next pipe the output of that to grep to show only the lines containing a search term ("org.springframework" in this case):
tail -f logfile | grep org.springframework
The third step I'd like to make is piping the output from grep to a third command, '...
Here's a bash script I'm working on:
dir="~/path/to/$1/folder"
if [ -d "$dir" ]; then
# do some stuff
else
echo "Directory $dir doesn't exist";
exit 1
fi
and when I run it from the terminal:
> ./myscript.sh 123
Directory ~/path/to/123/folder doesn't exist
But that folder clearly does exist. This works normally:
> ls ~/...
I want to launch a background Python job from a bash script and then gracefully kill it with SIGINT. This works fine from the shell, but I can't seem to get it to work in a script.
loop.py:
#! /usr/bin/env python
if __name__ == "__main__":
try:
print 'starting loop'
while True:
pass
except KeyboardIn...
I'd like to create a setup on my local machine (Ubuntu GNOME) whereby the terminal window has a different background color depending on whether I'm logged in to my local machine or ssh'd into a remote machine.
Is there a way to do this?
...