A script is a sequence of commands or instructions that are executed by an interpreter program rather than compiled into a standalone executable program.

learn more… | top users | synonyms (1)

4
votes
2answers
1k views

System calls, AWK, and Bringing in external inputs

awk '{ TEMPVAR="/usr/bin"; printf("%s", system("ls $TEMPVAR")); }' empty In this example I'm trying to bring in the variable TEMPVAR into the system call. How would I do this? What I'm aiming to ...
13
votes
1answer
958 views

Shebang line with `#!/usr/bin/env command --argument` fails on Linux

I've got a simple script: #!/usr/bin/env ruby --verbose # script.rb puts "hi" On my OSX box, it runs fine: osx% ./script.rb hi However, on my linux box, it throws an error linux% ./script.rb ...
3
votes
2answers
2k views

If Statement with 2 Variables - Bash

I am trying to write a single IF statement which can check two variables at once. I have two variables, for example: $VARA $VARB Both with either contain a 0 or a non 0 value. I need an if ...
27
votes
7answers
1k views

What's the equivalent to && when writing a bash script?

I apologize in advance if this is a duplicate question. I did make an effort to search/check before asking here. I'm comfortable with writing one-liners like this: foocommand && ...
5
votes
3answers
493 views

bash -e exits when let or expr evaluates to 0

I have a bash script that sets -e so the script will exit on any exit status != 0. I'm trying to do some basic shell arithmetic assigned to variables and sometimes the expression equals 0 which ...
3
votes
1answer
151 views

Issue when setting a default path in BASH

I have a BASH scripting question. I'd like the mention that I am new to BASH scripting; however, I am not new to programming. I am developing a simple BASH script to watch a given compass project. My ...
4
votes
3answers
898 views

Why can't I source a script file from .xsessionrc?

I am running LXDE/Openbox on Debian Linux. On logging in I want to: add a user specific directory to the $PATH variable (A) execute some (non-graphical) commands (e.g. mount directories) (B) The ...
2
votes
2answers
480 views

Averaging output of dstat

I need to average upload and download speed using dstat -n. How can I add all the received and sent data sizes that appear after dstat -n, so that I can add them and find average upload and download ...
1
vote
2answers
847 views

How to use an optional argument?

I'm writing this script to work as a fast draft. It opens my text editor with date and time, so I can insert some draft text to save quickly. 1. At first I'd like to append the date and time at the ...
0
votes
1answer
193 views

How do I write a script to keep retrying Yum Update Program?

My job let me always release a new version of the program to a satellite server, then in the running server, I use yum update program to update the program. However, due to unknown reason, in most of ...
5
votes
4answers
478 views

Testing, from a script, if audio devices are in silent?

Is there a default program where I can check if my audio devices are in silent? Edit: By silence, I mean that if there is something playing on that (not just activated or opened) Something like ...
3
votes
2answers
2k views

Determining if a host is online

I'm testing stability of a machine and I need way to simply write a Bash script to determine if a host is online or not. How could I script this? if [ ! $(hostisonline) ]; then # profit fi
1
vote
1answer
104 views

Frequent command “template”: remove parameter expansion escape characters

zsh newbie here... I find myself using a handful of long commands over and over again with slightly different arguments. For example: rsync -havu --progress --rsh='ssh -l mylogin' ...
2
votes
2answers
190 views

Script to choose editor to open file based on the argument

I'd like to run my script fastex with two possible arguments (g or t), like fastex g. Based on the argument I want to call geany $file or texstudio $file. This is to choose the editor. I tried ...
1
vote
2answers
756 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
199 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 ...
5
votes
2answers
165 views

How to consistently start Vim's command line to make a mapping work in any mode?

I try to normalize access to Vim's command line mode from any other mode in order to simplify my actual mappings. For example to make the <f6> key work from anywhere I define the following ...
6
votes
1answer
242 views

How to change Vim's command type mode programmatically?

Is there a simple way to switch from one command type mode to another without loosing the current command line? In my ~/.vimrc file I remap the <space> and <c-space> character, coming ...
3
votes
3answers
2k 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 ...
0
votes
2answers
144 views

fwui.log error while running this script

I run this bash script in order to put all the files with the following format dated today in the same folder. for example here I want 2012-12-17_083213 to be my folder and then inside it I have the ...
3
votes
2answers
422 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 ...
6
votes
3answers
826 views

Difference between commands in bash script and commands in terminal

Are there any differences between commands that you type into the terminal and commands you include in a script?
2
votes
1answer
187 views

Access the Shift-Insert clipboard from script

How do I access the Shift-Insert (paste) clipboard from a script? You can see what I use here. Edit: A demonstration how it works, with xclip: echo hello | xclip -selection secondary xclip -o ...
1
vote
2answers
2k views

Scripting VMware configuration: can I use PowerCLI?

I have an automated task to start, it involves various commands in PowerCLI. like Allocate Space New-Datastore Parameter(1) Browse Datastore Get-Datastore Parameter(1) Remove file ...
2
votes
4answers
151 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 ...
7
votes
1answer
848 views

Problems running python script from motion

I'm trying to set up the raspberry pi with my webcam as a motion detecting cctv that uploads the videos to google drive using Jeremy Blythe's script I have motion working correctly and the python ...
2
votes
1answer
76 views

required output not achieved by bash script

I am new to bash script and want to create bash script that moves some days old files between source and destination as per days defined in script. #!/bin/bash echo "Enter Your Source Directory" ...
2
votes
1answer
126 views

How to set Cols and Lines for a Subprocess

I have a script that runs a series of scripts numbered 001,002,003,004... etc down to 041 right now, will be more in the future - and these scripts them selves use some cursor control to print a ...
1
vote
2answers
231 views

Bulk Adding Users to Groups

Let's assume I have a Linux box configured as a primary domain controller with 50 users connecting at any given time. If I wanted to create two groups, one called "Teachers" and the other "Students" ...
0
votes
1answer
813 views

Bash script to copy *.log files into a new directory

I have some files like this: 2012-12-17_083213_1.log 2012-12-17_083213_1.log_stats 2012-12-17_083213_1.logaccount_ptr 2012-12-17_083213_1.loginitial_ptr 2012-12-17_083213_1.logptr ...
1
vote
1answer
170 views

How to reference a script-local dictionary in a Vim mapping?

Somehow I'm not able to execute the following mapping: function! s:MySurroundingFunctionIWantToKeep() let s:Foobar={'foo': 'bar'} map \42 :echo <sid>Foobar.foo<cr> endfunction call ...
3
votes
1answer
345 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 > ...
2
votes
1answer
644 views

permission denied executing script over ssh

When a web page is loaded on server A i want it to run a script on server B. I can do this with a series of commands from server A by logging into server B and executing the script, but it needs to be ...
20
votes
1answer
837 views

How to implement a horizontal cat? [duplicate]

Standard cat concatenates files line by line (row by row, if you will). I find myself needing a horizontal cat command more and more often recently; i.e. a command that takes a list of files and ...
0
votes
1answer
95 views

why there is random behaviuor for a background job?

going through advanced bash scripting guide example 3.3 running a loop in background, i found this : #!/bin/bash # background-loop.sh for i in 1 2 3 4 5 6 7 8 9 10 # First loop. do echo -n "$i " done ...
1
vote
1answer
332 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
2answers
2k views

grep output of expect script

I'm trying to run some expect language, and grep/parse the output all in one script. I want to grep the output of and look for "error" (I should note that standard linux commands like awk, sed, grep, ...
5
votes
1answer
2k 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 ...
0
votes
1answer
350 views

Unix cp wildcard with directory structure [duplicate]

Possible Duplicate: How can I copy a subset of files from a directory while preserving the folder structure? I have a bunch of directories like this: /Artists/Example Name ...
1
vote
3answers
119 views

Script to insert line into files in sub-dirs

I have a sub-dir tree with varying number of branches and most of the branches contain .cpp files (many of them). I have a header-file at the root of the tree that I want to have as a #include ...
1
vote
2answers
336 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
331 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 ...
1
vote
2answers
888 views

“PING” an AP to see if it's alive? (Before associate with it)

I would like to detect if a certain AP address is alive, i.e. by "PING" its SSID or MAC address (both known). What program can I use to achieve that? I'm making a simple script that run as root. (I ...
1
vote
2answers
2k views

how do I run a cron job with a specific user?

My cron and scripting skills are very poor, but I need to run a job every 5 minutes by user 'cpc'. So I created a script and left it at /root. My crontab -e entry about it is: 0-59/5 * * * * ...
2
votes
1answer
2k views

Email picture attachments as inline along with the email body

I'm right now working with a script for emailing attachment (.png pics). Since I'm using mutt command with -a option, the email is sent as a mail attachment. I want these .png pictures to be mailed ...
2
votes
1answer
1k views

Script to get file from SFTP and run it

We have 5 servers running our code: A, B , C, D and E. From a local machine, we sftp the file to A. Then ssh id@A su - applicationname sftp id@A get <file> bye tar -xzf <file> logout ...
2
votes
2answers
445 views

How to traverse a file and extract words using their index?

The given file must not be stored in variable and then traversed due to memory size restrictions: Example: var=$(cat FILE) for i in $var do echo $i done How do you traverse all strings in a file ...
2
votes
1answer
747 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 ...
1
vote
0answers
531 views

Cron file syntax checker/validator script

Does anyone know a script (bash, perl, php ...) to validate the syntax of crontab files? I found this http://www.intuitive.com/wicked/showscript.cgi?053-verifycron.sh but just Vixie cron notation is ...
1
vote
0answers
156 views

Having problems with script and redirecting input to stdin [closed]

EDIT: found mistake, it was actually bug in my program, I had > instead of >= in my for loop that reads coefficients. I'm fairly new to linux, and I need help with bash scripting. I have C program, ...