Tagged Questions
2
votes
4answers
56 views
Delete all files in directories except those whose path are listed in a file
Given the following files:
data/A/a.txt
data/B/b.pdf
...
date/P/whatever.log
...
data/Z/z.jpg
I would like to delete all files in the data/A/, data/B/, ..., data/Z/ directories except those files ...
3
votes
2answers
51 views
Running commands after event based outputs
there are commands like
iwevent
or
tcpdump -n src host x.x.x.x
that send to the stdout some lines when something happens. Is there any form of running some command inmmediatly after a ...
1
vote
1answer
31 views
Script ends abruptly with a Terminated message
This is my bash script. All it does is to check whether a service has started and whether some processes are running as expected.
It ends abruptly with a Terminated message. I tried debugging it ...
2
votes
3answers
65 views
Concatenate files in multiple matching subdirectories
I need to concatenate files based upon the name of the subdirectory they are in.
The subdirectories sometimes have duplicates and sometimes don't.
The file structure looks like this:
RootDir
633
...
8
votes
2answers
222 views
Regular expression in bash script
This is my first time bash scripting so I'm probably making an easy mistake.
Basically, I'm trying to write a script that gets the groups of a user, and if they are in a certain group, it will log ...
2
votes
2answers
59 views
Sanitize Apache access log files?
We have this code in a shell script that pipes output for Apache to log.
declare -a values=( $taintRequestVals )
for item in ${!values[@]}
do
cat $apacheLog | sed ...
1
vote
2answers
110 views
how can I add (subtract, etc.) two numbers with bash?
I can read the numbers and operation in with:
echo "First number please"
read num1
echo "Second mumber please"
read num2
echo "Operation?"
read op
but then all my attempts to add the numbers fail:
...
1
vote
2answers
44 views
(Ill)Logical statement
I am attempting to make a simple script to flip my computer screen. My first if statement executes perfectly, but after that, thought $istouch is "on", the elif statement block will not execute! I ...
0
votes
2answers
62 views
Bash shell scripting basic question regarding the syntax and basename
Consider the script below:
myname=`basename $0`;
for i in `ls -A`
do
if [ $i = $myname ]
then
echo "Sorry i won't rename myself"
else
newname=`echo $i |tr a-z A-Z`
mv $i $newname
fi
done
...
5
votes
3answers
72 views
Maintain (or restore) file permissions when replacing file
I have a command that accepts a file as an argument, modifies the file, then writes it to the file name specified in the second argument. I'll call that program modifyfile.
I wanted it to work "in ...
4
votes
3answers
401 views
Summing up an array inside of awk?
I have the following piece of code:
sum1=
sum2=
declare -a a
echo $temp | awk '{split($0,a,","); name=a[1] ; for(i=2;i<=4;i++) sum1+=a[i] ; for(i=5;i<=7;i++) sum2+=a[i] }'
This code is ...
2
votes
1answer
111 views
bash: integer expression expected
I have a file out.csv I have to check if the name inputed by user exists in the file(comma separated) or not. I am taking name using read but while checking for equality I am getting error
...
3
votes
4answers
119 views
Capture output of a bash command, parse it and store into different bash variables
Explanation:
I have a small bash script which simply runs any Linux command (e.g. say ifconfig)
The typical output of ifconfig is something like this:
eth0 Link encap:Ethernet HWaddr ...
2
votes
2answers
70 views
screen /bin/bash execute script and then go to interactive shell
I am using .byobu/windows to start up some screen sessions, and I'm trying to start a script that will exit to an interactive shell once it has completed. Is this possible?
I've tried:
screen -t ...
3
votes
2answers
103 views
bash equivalent of zsh's $@[2,$#]
(NB: the motivation for this question is only to improve my bash programming know-how.)
I want to know the bash equivalent of zsh expressions such as $@[2,$#], which directly address a range of a ...