Tagged Questions
1
vote
3answers
67 views
sed - how to replace a single quote?
This works fine:
sed -i 's# @driver.find_element(:xpath, "//a\[contains(@href,##' temp_spec.rb
against a source of
@driver.find_element(:xpath, "//a[contains(@href,'change_district')]").click
...
-1
votes
0answers
49 views
shell scripts in linux [closed]
The "time and network" script
•Find the current time.
•If the current minute-of-the-hour is greater than 30, then use ifup to enable all network interfaces, otherwise disable all network interfaces ...
1
vote
2answers
45 views
Direct recursive shell script output to each subdirectory, not parent directory
I'm processing a batch of subjects data recursively, calling the script within the parent directory.
For example, I have the parent directory:
/home/subjects
and the subdirectories which contain ...
2
votes
1answer
39 views
Invoking a script with ld-linux.so?
I just downloaded a tar file that is supposed to include everything required to run a program that we can call some_binary. I extracted it's contents, and I see the following:
A binary (let's call ...
4
votes
3answers
70 views
CD into directory from HISTORY in a bash script or alias e.g. $(!!)
I often want to change into the directory of a file on my file system, but I'm not sure where the file is.
I search for it like so:
find -type f -name "myfile.txt"
Lets say for the sake of ...
3
votes
1answer
134 views
Increase %e precision with /usr/bin/time shell command
When I run the time command in shell time ./myapp I get an output like the following:
real 0m0.668s
user 0m0.112s
sys 0m0.028s
However,when I run the command \time -f %e ./myapp I lose ...
1
vote
1answer
126 views
How to match 2 large file and print the difference in shell script
I have 2 files.
File1 has 400k numerical records.
e.g:
1
2
3
4
5
6
.. and so on
File 2 also has 420k numerical records.
e.g:
1
2
3
4
6
.. and so on
Both these file are in unsorted manner. I want ...
1
vote
2answers
299 views
How to correctly concatenate strings in shells script?
I have a bash shell which I need to modify, and I have to set a variable in a script and then call another script. My variable, EXTRA_JAVA_OPTIONS must be
-javaagent:myagent.jar="-d 0 -i 1000 -l log2 ...
1
vote
3answers
103 views
Rerunning the same command with a different parameter
I know that I can run the following command
ls Some{File,Folder}
And it is equivalent to running this:
ls SomeFile SomeFolder
(I also use it a lot for things like mv place_{a,b})
However, I was ...
2
votes
2answers
261 views
Check whether files in a file list exist in a certain directory
The runtime arguments are as follows: $1 is the path to the file containing the list of files
$2 is the path to the directory containing the files
What I want to do is check that each file listed in ...
3
votes
2answers
276 views
Run shell scripts through a website
I have been reading and searching on what is the best way to run my shell scripts through a website.
My goals are as follows:
Browse a folder
Select folder or contents
onclick will run script
...
2
votes
4answers
114 views
store and execute redirection/piped command in script
How do you store, and later execute, a command with redirection and and a pipe? (And is it the pipe, or the redirection, or both, that's causing my problem?)
I tried to print the urxvt version in a ...
3
votes
1answer
158 views
Split file based on a pattern with leading zeros
I have a book in text format. I would like to split the book into several files where each file contains a single chapter. Therefore I'm using the following command:
awk '/Chapter/{i++}{print > ...
1
vote
1answer
127 views
What is difference between POSIX and bash and other shell scripts?
While going through many answers on Unix.SE, I come across many of them writing their contents w.r.t to Posix or Bash or some other standard. I know of some differences like some have arrays and some ...
2
votes
1answer
178 views
Trouble in script with spaces in filename
I've got a script that scp's a file from remote host back to local. Sometimes the file names contain spaces. scp does not like spaces in its file names. For some reason my attempts at handling the ...
1
vote
2answers
135 views
How can I find matches with sed (or similar) for configuration parameters?
I'm pretty good at using php's preg_match (and similar) commands, and I'm also pretty good with regular expressions, but I don't do very well with sed.
I have two shell scripts I'm working on and I'd ...
4
votes
4answers
198 views
List any file ending with .in and corresponding .out with shell script
I have a directory full of files ending with different extensions, how would I list/select only the files ending with .in and corresponding .out that share the same basename?
e.g.
file1.txt
file1.in
...
2
votes
1answer
189 views
intersection of two files according to the first column
I have two files
in file A, there are sequence_numbers
in the other file B, there are many columns, and the first column is sequnce numbers,
I want to get a files with all the lines in the B with the ...
3
votes
3answers
141 views
“Virtual” shell, ie. jailing an user inside a process
The title might not say much about the issue at hand so let me get straight to the point.
Let's assume I have a casual user who can log in to the system via SSH into a bash shell. I also have a PHP ...
2
votes
1answer
270 views
Execution time of pi calculation in shell scripts
I have to run a couple of command lines on a shell script on Ubuntu,
one of those is a pi calculation.
It works fine when i run it on terminal via the following cmd line:
time echo ...
2
votes
2answers
306 views
Parse apache logs to exclude IP ranges
I need to look for some requests in a huge pile of apache logs. My only requirement is this:
I need to only view the requests coming from any IP address that is NOT included in a list of 50 IP ranges ...
0
votes
1answer
354 views
Shell script to recursively grep data from certain files in the directory and return values to file [closed]
I am making a simple shell script which will minimize the time I spend in searching all directories under a parent directory and grep some things inside some files. Here's my script.
#!/bin/sh
...
14
votes
6answers
1k views
The most universal scripting language for Linux is?
We are writing scripts for Linux systems, there has been some debate over what would be the most universally Linux present scripting language to use. Bash, SH, Posix? What?
3
votes
2answers
3k views
Execute shell script from php, as root user?
Need to execute the following line from PHP:
$res = shell_exec('sudo sh /home/nicklas/cronjobs/make_account.sh
username password');
The problem is nothing happens on execution. If i try to ...
4
votes
3answers
833 views
Check if script is started by cron, rather than invoked manually
Is there any variable that cron set when it's running a program ? If the script is running by cron, I'll skip some parts; otherwise invoke those parts.
How can I know if the bash script is started by ...
2
votes
4answers
430 views
chown all files based on file name pattern in current directory
I'm trying to chown all files whose filenames begin with ChownFileNames. I've used this command, but it doesnt seem to work:
find . -maxdepth 1 |grep 'ChownFileNames*' -exec chown hadoop:hadoop -- {} ...
2
votes
1answer
534 views
Shell script filtering through jpg files attributes
I'm trying to find a way to filter through thousands of jpg files, and keep only the files with a certain attribute (such as the camera brand with which the picture was captured). How can I do so?
3
votes
2answers
198 views
issues with GNU tail -f and combination of commands
$ tail -f /logs/filename.log | awk '!(/list)'
I am able to run this command in GNU Linux flavour
But when I written in a script it is not working.
test.ksh:
variable="/logs/filename.log | awk ...
4
votes
3answers
442 views
What does the following Bash script mean/do?
What does the following script mean?
exec 4<&0 0</etc/XX/cfg
read line1
exec 0<&4
UPDATE
Thanks for the answer, just one part I'm not sure:
It redirects fd0 to fd4, and ...
3
votes
2answers
239 views
List of script( location)s that get run automatically, and when?
Does anybody know (of a resource listing) what scripts are run automatically, and when, from the moment I startup the computer until it's shutdown again.
I know several places where I can add scripts ...
4
votes
6answers
1k views
Linux script or program to shorten filenames
I haven't had much success in finding a Linux version of namemangler, which I need to rename 1000 of files so they are readable on Windows.
Does anyone know of a Linux program that can do this?
If ...
1
vote
3answers
2k views
Pass command line arguments to bash script
I am new to bash script programming.
I want to implement a bash script 'deploymLog', which accepts as input one string argument(name).
[root@localhost Desktop]# ./deploymLog.sh name
here I want to ...
-1
votes
2answers
159 views
Shell programming temp=$1 vs temp=1
What's the difference between temp=$1 and temp=1? Why do I need the dollar sign?
For example:
#!/bin/bash
temp=$1
cell=$((($temp-32)*5/9))
echo $cell
1
vote
2answers
448 views
Issue with mv command in a script
This must be a very simple issue to solve, but I am stuck (not a UNIX pro). I need to move a gz to a target directory, but I get a No such file or directory.
NOW=$(date +"%Y-%m-%d-%T")
...
1
vote
2answers
206 views
$2 (field reference) in awk BEGIN is not working
In the following snippet, $2 in awk is returning empty. What am I doing wrong? I am trying to find the difference between MAX and MIN.
#!/bin/ksh
if [ $# -ne 1 ]; then
echo "Usage: sh ...
4
votes
1answer
218 views
Efficient way of comparing in awk
#!/bin/awk
BEGIN {
while(getline var < compareTo > 0)
{
orderIds[var]=var;
}
}
{
if(orderIds[$0] == "")
{
print $0;
...
3
votes
3answers
1k views
How do I run a script n times at same time and how do I simulate a semaphore?
I have a text file, inside of this file is a number, and I have a script.sh in ksh.
The script reads the file and gets the number, then increases the number by 1 and overwrites the new number in the ...
6
votes
2answers
914 views
List elements with spaces in zsh
I've been studying zsh scripting for all of 2 hours at this point and I've hit a wall. I want to go through a list of files that may have spaces in them. I'm open to completely different approaches ...
1
vote
1answer
137 views
How to access user's fpath as opposed to system's fpath with a script?
test.zsh:
#!/usr/bin/env zsh
for f in ${fpath}; do
echo ${f}
done
outputs:
...
3
votes
2answers
345 views
Convert a typescript file to a list of commands (history)
I wanted to record a linux session so I could use it as documentation for a "how to install" guide. I found something on the internet that suggested that the script command would be good for this, and ...
9
votes
2answers
922 views
Confusing use of && and || operators
I was skimming through an /etc/rc.d/init.d/sendmail file (I know this is hardly ever used, but I'm studying for an exam), and I've become a bit confused about the && and the || operators. ...
15
votes
3answers
2k views
How do I exit a script in a conditional statement?
I'm writing a bash script where I want to exit if the user is not root. The conditional works fine, but the script does not exit.
[[ `id -u` == 0 ]] || (echo "Must be root to run script"; exit)
...
5
votes
3answers
320 views
What does the syntax on this shell command with extglob mean?
In
Building paths robustly,
A solution is proposed that includes:
shopt -s extglob; dir="${dir//+(\/)//}"
Can someone explain (parse) that for me? I understand what it's doing, but not how the ...
6
votes
3answers
1k views
How to “send” variable to sub-shell?
I run the following script:
VAR="Test"
sh -c 'echo "Hello $VAR"'
But I get :
# ./test.sh
Hello
How can I "send" the variable VAR of my script to the shell created with sh -c?
2
votes
2answers
2k views
How to exclude a list of full directory paths in find command on Solaris
(Duplicated from Stack Overflow: http://stackoverflow.com/questions/7854975/how-to-exclude-a-list-of-full-directory-paths-in-find-command-on-solaris)
I have a very specific need to find unowned files ...
1
vote
2answers
135 views
How to log if an environment variable is unset? [closed]
How can I write a shell script that checks for an environment variable and writes to a log file if the variable is unset?
Also, if the file name pointed by env variable doesn't exist, how to create ...
1
vote
3answers
316 views
Evalute passed in variable in bash
Is there a way to pass in a variable as an argument to a bash script and have it evaluated scoped by the bash script?
Given:
# cat /path/to/file/of/host/names
bob
tom
joe
etc...
# dofor
FILE=$1
...
4
votes
4answers
455 views
Last failed command in bash
The $? variable holds the exit status of last run command. Is there a variable that holds last run command itself?
5
votes
5answers
348 views
Shell programming, avoiding tempfiles
I often write KSH shell scripts that follow the same pattern:
(1) retrieve output from one or more command
(2) format it using grep|cut|awk|sed and print it to the screen or to a file
In order to ...
2
votes
2answers
206 views
Comparing files and their properties
I get information of a certain set of files in my mail every day, which looks like this:
58623208 Sep 14 20:08 blbn_blfbe_drv
57904920 Sep 14 19:54 blbn_cycmn
55814208 Sep 14 06:02 clsa_Upd
38912000 ...

