Tagged Questions
0
votes
1answer
19 views
Script to find the default Desktop Environment?
What is a distribution agnostic snippet of code to find the default Desktop Environment or better yet, the DE last used. The code must run from a remote SSH session or CTRL-ALT-F2 text only console. ...
0
votes
0answers
23 views
Variable Substitution in sed [duplicate]
I have this script and I need to count the lines inside a file, then pass the number of lines counted to a for loop so that I can get the contents of each line and put it in a variable.
My question ...
2
votes
2answers
73 views
How to put the following information in a CSV file?
I have a text file with the following type of content:
OPERATION_CONTEXT VMD1HTE1A71_ns:.oc.GJ_OAD2 alarm_object 1130
On director: VMD1HTE1A71_ns:.temip.VMD1HTE1A71_director
AT Fri 18 Oct 2013 ...
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 ...
0
votes
2answers
43 views
Run level script - Help
I want the following command to be ran, as soon as system boots.
glances -s -P redhat &
How to achieve that?
I tried writing a run level script which didn't work as expected.
-1
votes
2answers
57 views
Make a new sniffer [closed]
How can use the Linux-kernel to supervise what is going on, about the new connections, new ports, connected hosts? Like I will do a new sniffer.
Which files should I monitor to know what is going ...
2
votes
2answers
81 views
Optimized way to list and delete files
I need to list and delete .php, .xml files. For this I am using find command.
To list :
find . -type f -name \*.php -print0
To delete :
find . -type f -name \*.php -print0 | xargs -0 rm -r
As I run ...
5
votes
2answers
94 views
How does this find command using “find … -exec sh -c '…' sh {} +” work?
@StephaneChazelas posted the following solution to this Q&A: Having some trouble using “find -exec {} +”.
$ find . -iname "*.extension" -exec sh -c '
exec <command> "$@" <additional ...
1
vote
3answers
59 views
How to add Multiple Searches in AWK command
Im trying to search for the files Created in June,July and August months. I used this method
ls -lrth|awk '/[Jun][Jul][Aug]/ {print}'
but it ain't working.
Please help me correct the syntax.
2
votes
1answer
50 views
Regular Expressions within a string in AWK using if/then control structure?
PROBLEM
I want to specifically use AWK (GAWK, MAWK, whatever) in an AWK script to sum up the values in field 9 for every record that contains "runner__.jpx" (the underscores are placeholders for two ...
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
...
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
135 views
Shell script to validate mount point status in the linux server
I'm in need of a script which should work as below.
A script where it would validate if that specific mountpoint is currently mounted on the server. It would search for mountpoint name in /etc/fstab ...
3
votes
1answer
57 views
How can I write a sed script to delete numbers from a line?
Sample File
a.b.gg3d 0000000001 0000000001 y
a.b.112a 0000000000 0000000001 y
a.b.gg3s 0000000001 0000000001 y
a.b.1111 0000000000 0000000001 m
I have a file that includes about three thousand ...
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
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 ...
1
vote
3answers
77 views
Confused on user and su in linux
How could I run a script as a specific user (non-root)? As this?
sudo su - john /usr/share/script.pl for user john?
-1
votes
1answer
172 views
if condition, loop in grep [closed]
Could someone please provide help for me.
I tried to start writing a shell script but am getting hung up with this issue.
I need to grep commands "adb shell ps" and find in it 3 processes with names:
...
2
votes
2answers
383 views
Checking and changing file permission with script
I'm new to bash and I can't get a script working. This is the code that I have:
#!/bin/bash
file=~/scripts/text.txt
if [ -e $file ]
then echo "The file exists"
elif [ ! -e $file ]
then echo "The ...
1
vote
0answers
49 views
Is it possible to have comments in multiline commands in fish?
In bash it's possible to do
my_function() {
echo "hello" |
#remove 'l'
tr -d 'l'
}
but in fish ( http://fishshell.com ) I wasn't able to do the same:
function my_function
echo "hello" | ...
2
votes
1answer
60 views
Passing values to a parameter in script
Following is the script to copy all libraries of a certain command to make my chroot environment.
For example:
./cplb.sh /bin/ls will copy all the libraries of ls command (i.e., the files listed by ...
4
votes
1answer
89 views
How Can I Automate the Change between a Python Script and a Nohup Python Script?
I have a Raspberry Pi connected to a digital temperature probe, which measures my fermenting beer. A python script reads the temperature every second and prints it to the console, and stores it in a ...
1
vote
1answer
52 views
Missing “Run in terminal” in KDE
I switched to KDE from Gnome after seven years using the latter. I have everything configured already but I'm missing one option: the run in terminal prompt, when executing a script double clicking.
...
5
votes
3answers
124 views
${#array} vs ${#array[@]}
As far as I can tell both ${#array[@]} and ${#array} evaluate to the number of elements in $array. Is there any reason for preferring the longer form (${#array[@]})?
5
votes
2answers
101 views
Is there a less convoluted way to set the $path array locally within function?
Is there a less laborious way for setting a local version of the $path array than what's shown in the following snippet?
foo () {
local holdpath
holdpath=($path)
local path
...
0
votes
1answer
141 views
Why is my shell script hanging on `apt-get -y upgrade`?
Ubuntu :
sudo DEBIAN_FRONTEND=noninteractive apt-get -y update
sudo DEBIAN_FRONTEND=noninteractive apt-get -y upgrade
sudo reboot
Script is always interrupted after upgrade and then it will stay on ...
12
votes
3answers
231 views
When to use redirection to stderr in shell scripts
I know that well-behaved utilities like grep output "normal" messages to stdout, and error messages to stderr.
$ grep '^foo' file1 file2
file1:foo
grep: file2: No such file or directory
When I'm ...
-2
votes
2answers
308 views
Loop over multiple addresses: ping and drop data into file
I would like to be able to have a script that will:
look at a list of IP addresses
Ping one of the addresses
Take the data and drop it in to a file
Move on to the next IP
So far I have:
cd ...
2
votes
1answer
196 views
Ssh to a box, run a command, output data to a file, then move on to the next IP adress [duplicate]
I want to run a script from my Jump server, have it SSH to a server, then run a command (like rm <file>, top or ls -lsa) then take that output and put it in to a file on my Jump server then move ...