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 (2)

1
vote
1answer
468 views

Securely reading and parsing a string from a parameter or file in bash

I've been writing a number of bash scripts lately which get variables from a parameter or from a file. Some of the scripts run as root (using sudo) This is on my notebook, so there aren't any other ...
3
votes
1answer
372 views

Searching for Failed attemps in /var/log/secure

I'm currently writing a script to examine /var/log/secure file and report how many failed attempts there were that day. I need to output it in the following format: Date: 03/15/10 Time: 10:30 Number ...
1
vote
1answer
4k views

How can I find and filter a specific column in a .csv file? [duplicate]

I have .csv files with the following structure: cat,dog,mouse,pig,bird,cow,... 21,34,54,566,78,1,... 23,10,12,569,56,4,... 32,20,13,123,56,3,... 34,30,44,322,66,2,... I want to filter the column ...
6
votes
4answers
3k views

Split PDF into documents with several pages each

There are several resources on the web explaining how one can split a PDF into many files with on page per file. But how can you split them into chunks of, say, five pages each? I have looked into ...
1
vote
1answer
128 views

Sort aligned columns

I have a program which output looks like this # Status VAL1 VAL2 Description 1 some text 2.5 4.4 Some long other text 5 some text 2 14.5 2.0 Some long other ...
1
vote
4answers
241 views

Where to put a background script

I have a script that i want to be constantly running in the background but I don't know where to launch it from If I put it in .bashrc it will run multiple times (one for each login) It's an ...
2
votes
1answer
3k views

Create sub-directories and organize files by date

I have some directories of files copied from my security camera that I would like to organize into sub-directories by file date. So for example; -rwxrwxrwx 0 root root 4935241 Jul 19 2012 ...
1
vote
2answers
317 views

find total ram memory and swap memory

I need to write a script to find total memory and total swap of several linux server (2000+). I have one trusted server from where I can login to all these 2000 servers without a password. When I run ...
9
votes
5answers
2k views

How can I have more than one possibility in a script's shebang line?

I'm in a bit of an interesting situation where I have a Python script that can theoretically be run by a variety of users with a variety of environments (and PATHs) and on a variety of Linux systems. ...
0
votes
2answers
318 views

ipset not executing from crontab

I have this txt files that contains IPs, one per line of file, that I want to block using ipset. I have this bash script that essentially reads from the plain txt file and constructs an array. Then ...
1
vote
2answers
423 views

At login, take picture of user at Login window(loginGUI promt window)

I have code to take a picture in a script. I don't understand how to run this script at the time of login. I would like to modify the login process so that: The user gets 3 login attempts. After 3 ...
5
votes
3answers
1k views

Where are userspace programs supposed to save their logs?

I am writing a script that I want to run without privileges. I want the errors that the script encounters to be logged to some log file. I do not not have privileges to write one to /var/log. And I do ...
25
votes
4answers
5k views

Universal Node.js shebang?

Node.js is very popular these days and I've been writing some scripts on it. Unfortunately, compatibility is a problem. Officially, the Node.js interpreter is supposed to be called node, but Debian ...
1
vote
1answer
610 views

Running a script as Grub boot option

I'm assembling some DR stuff for my Linux boxes. One item that would be really handy would be a GRUB option that would run a script to change my boxes from static IPs to dynamic. I know we could do ...
4
votes
2answers
649 views

Comparing two columns with two columns

I have a file that I need to compare the values in two columns with another two columns. For examples: Item A B C D 1 201 3101 3101 201 2 3101 201 202 3101 3 3101 201 ...
2
votes
1answer
419 views

bash scripting add arguments

I have created a script which takes parameters and arguments. I want to insert the --help argument. I already know how to parse normal arguments with -, but I don't know how to parse the -- ones. to ...
4
votes
5answers
5k views

How can I split a text file into multiple text files using Perl?

I have a file ABC_TabDelim.txt that contains the following: 00:00:00:00 00:00:05:00 01SC_001.jpg 00:00:14:29 00:00:19:29 01SC_002.jpg 00:01:07:20 00:01:12:20 01SC_003.jpg 00:00:00:00 00:00:03:25 ...
4
votes
2answers
6k views

Iterate over multiple parameters with spaces in bash script

I have a bash script for my RaspberryPi (running Raspbian) that is supposed to take multiple file names as parameter(s) and play one after the other (using omxplayer). The basic structure is this: ...
2
votes
1answer
321 views

Open kickoff via shell/script

Is there any (undocumented) way to open the KDE Kickoff menu via dbus or some similar mechanism?
1
vote
1answer
2k 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 ...
4
votes
2answers
4k 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 ...
18
votes
1answer
3k 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
6k 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 ...
29
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 && ...
6
votes
3answers
1k 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
220 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
2k 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 ...
3
votes
3answers
723 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
3k 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
306 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
1k 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 ...
4
votes
2answers
3k 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
116 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
244 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
3k 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
4answers
567 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
266 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
337 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
6k 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
174 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
657 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 ...
8
votes
3answers
2k 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
233 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 ...
2
votes
2answers
4k 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
196 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
2k 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
79 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
285 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
495 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
1k 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 ...