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)

0
votes
2answers
1k views

Need help to make rows into column with awk or sed

Recently, I look for scripts to take this: This; Is; First; Line; and make it like: This Is First Line
0
votes
2answers
244 views

Autentification on SSH connection in OneLine [duplicate]

Possible Duplicate: Shell Script for logging into a ssh server I need to connect via SSH to a remote server, however I must do this with out interactive mode and with out use Public keys ...
-1
votes
1answer
68 views

just wanted to know what am i doing wrong in the end of this script that doesnt put my checkdate in to cal command

#Purpose: Validate a date #Usage: chkdate year month day # if [ $# -eq 0 ]; then echo Usage: chkdate year month day exit 0 fi year=$1; month=$2; day=$3; extra=$4 if [[ "$extra" != "" ...
20
votes
3answers
10k views

What does it mean to have a $“dollarsign-prefixed string” in a script?

I just saw this in an init script: echo $"Stopping Apache" What is that dollar-sign for? My research so far: I found this in the bash manual: extquote If set, $'string' and ...
13
votes
7answers
10k views

Faster way than ping for checking if computer online?

I'm writing a wake on lan script for a set of our lab computers. We have sqlite db with a list of the computer hostnames, IPs, and MACs and currently I ping each of them with '-c1' so it doesn't run ...
8
votes
1answer
5k views

How to automatically record all your terminal sessions with script utility

What I want to achieve is be able to record my terminal sessions to file automatically whenever I use Yakuake/Konsole. It's easy to achieve if at the start of my session I do: script -f ...
11
votes
4answers
11k views

Script to change current directory (cd, pwd)

I want to run a script to simply change the current working directory: #!/bin/bash cd web/www/project But, after I run it, the current pwd remains unchanged! How can I do that?
8
votes
1answer
1k views

confirmed exit using trap

I am trying to trap the Ctrl+C signal asking a confirmation from the user. The trapping part works fine. But once the signal gets trapped, it does not return to the normal execution. Instead, it quits ...
5
votes
1answer
2k 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 ...
4
votes
2answers
502 views

Shell script printing the most visited directories

Is there a way to write a bash script with the following functionalities? Be launched when I press some key or key combination. (not so important requirement) Identify the 7 most visited directories ...
11
votes
3answers
724 views

How do you continue a sentence with a command inside

For example, I have been trying to say "There are 10 people online at the moment" in my script file. I can never seem to get the command working without the "people online at the moment" part on the ...
7
votes
4answers
4k views

Parallel execution of a program on multiple files

I have a small script that loops through all files of a folder and executes a (usually long lasting) command. Basically it's for file in ./folder/*; do ./bin/myProgram $file > ./done/$file ...
6
votes
2answers
903 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 ...
5
votes
4answers
179 views

Prefixing and appending blocks of text to a list of files

I'm trying to prefix and append blocks of text to a list of files. Here is where I am so far. The sticking point is the sed -i "1i \$prefix" "$file" && line. sed won't substitute the value of ...
5
votes
5answers
8k views

Parsing a delimited text file in bash as command arguments

I have a text file split up like so: field1,field2,field3 xield1,xield2,xield3 dield1,dield2,dield3 gield1,gield2,gield3 Each of these columns will be a parameter to a program, and I would like ...
3
votes
2answers
161 views

split a file, pass each piece as a param to a script, run each script in parallel

I have a words.txt with 10000 words (one to a line). I have 5,000 documents. I want to see which documents contain which of those words (with a regex pattern around the word). I have a script.sh that ...
2
votes
1answer
1k 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?
12
votes
2answers
9k 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. ...
9
votes
3answers
8k views

Invert boolean variable

I want to try simple script flag=false while !$flag do read x if [ "$x" -eq "true" ] then flag=true fi echo "${x} : ${flag}" done But when i run it, if i type true, i will see ...
7
votes
2answers
1k views

sync files recursively between two folders where files are less than 24 hours old

I want to find all the files under a directory which are within 24 hours then rsync those files with another server. There are some old files that I do not want to transfer, however if those old ...
7
votes
3answers
3k views

The way to use `/usr/bin/env sed -f ` in shebang?

Typing /usr/bin/env sed -f in terminal works. But if use it as a shebang, #!/usr/bin/env sed -f s/a/b/ The script will be fail to execute: /usr/bin/env: sed -f: No such file or directory I ...
7
votes
6answers
5k views

Extracting nested zip files

I have numerous zip archives, each of which contains a number of zip archives. What is the best way to recursively extract all files contained within this zip archive and its child zip archives, that ...
5
votes
1answer
2k views

Changing password in multiple boxes using script

I'm working in a environment which has around 400 AIX boxes. I don't have root access and I'm a normal user. The environment has no LDAP kind of centralized mechanism for authentication so the ...
4
votes
1answer
130 views

How to maximize a window programmably in X Window?

I'm wondering if there is any commands or programs to make some window maximized in X Window? For example, what I imagine is something like this xmaximize -window *window_id*
4
votes
1answer
83 views

How can I get information about my virtual desktops via the command line?

I'm curious how I can get information such as the dimensions of my desktop, which desktop is currently active, and what labels (if any) are set for my desktop enviornment (DE).
3
votes
5answers
276 views

How can I force a script to use more resources?

I'm running a very time-consuming script which takes many hours to end. Watching top I see that it's only taking 5% of the CPU at best, usually around 3%. Is there any way to force the script to use ...
3
votes
3answers
201 views

Permissions for a submission script

I'm a TA for an introductory Python programming class (all work is done from the terminal), and I'm writing a project submission script. Ideally I want a directory setup like this: submissions/ ...
3
votes
2answers
706 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 ...
2
votes
1answer
75 views

Get the full window dimensions (including decorations) in Unity

I have used the answer to How do I find the window dimensions and position accurately including decorations? in my bash scripts, and had good success with my Silentcast application on Xfce, but now ...
2
votes
3answers
1k views

Extracting characters after a particular text

I am extracting a page from website using cURL command. curl "www.google.com" -s | w3m -dump -T text/html > foo.txt The w3m command outputs the HTML page in a much more simpler format so that ...
2
votes
2answers
1k views

Concatenate multiple files under subdirectories

My directory structure is given below x:\Project_2012-158A\Sample_4041 SampleSheet.csv 4041_CGTACG_L002_R1_001.fastq 4041_CGTACG_L002_R2_001.fastq 4041_CGTACG_L006_R2_001.fastq ...
2
votes
4answers
2k views

Anacron job complains “Gtk-WARNING **: cannot open display”

I'm trying to make a simple weekly Anacron job that backs up my computer if I click yes on the dialog. The script I wrote works fine if run manually, but when Anacron runs it, nothing happens and I ...
1
vote
0answers
42 views

Neutralisation of data from Windows to Unix

I just noticed that other platforms files (Windows) had to cause me many bugs, like here, in my regexes. Mostly, the line ending ^M. There seems to be many ways to do dos2unix, like here described. ...
1
vote
1answer
52 views

How to write this replacement with condition

I want to replace now within my working directories the word -> with $\to$ if the word is not within verbatim environment. Pseudocode Replace all entriens of -> with $\to$ everywhere else but not ...
1
vote
2answers
101 views

How to notice log file changes with Linux standard tools? [duplicate]

I need something that does not need to be installed. It's on an embedded system with very little space on the HD. I can't instal anything. I need to do it with something that is already included. I ...
1
vote
2answers
912 views

How can I queue processes?

I have a surveillance camera and a program records videos when motion is detected. Basically, this program saves the video in a very heavy format. My solution was to call a script that converts the ...
8
votes
2answers
567 views

How to non-invasively test for write access to a file?

In a shell script, how do I easily and non-invasively test for write access to a file without actually attempting to modify the file? I could parse the output of stat, but that seems really complex, ...
7
votes
1answer
1k 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 ...
6
votes
1answer
316 views

Capabilities for a script on Linux

If I want to set a capability (capabilities(7)), such as CAP_NET_BIND_SERVICE, on an executable file and that file is a script, do I have to set the capability (setcap(8)) on the interpreter starting ...
5
votes
3answers
868 views

How to iterate through a list of files with spaces that is sorted (case insensitive)?

I am doing this in OSX which uses bash but obviously, not all bash conventions are used so hopefully your suggestion is available to me :) I have the following files fun bar1.txt Foo bar2.tXT ...
4
votes
2answers
133 views

When is 'if' not necessary?

In some scripts, I've seen if conditional statements written as: if [ some_conditional_statement ]; then # do stuff fi or [ some_conditional_statement ] && #do stuff Is the second ...
4
votes
3answers
205 views

shell script problem with using the operators

I am comparing two strings using the levenshtein distance algorithm. I got the PHP implementation of the algorithm from here. I am calling this php implementation from my shell script as below. ...
4
votes
2answers
253 views

Exiting a pipeline if a former command fails

I'm trying to check the number of running and queued PBS jobs by parsing the output of qstat -tn1 from a bash script. So far, this has worked: count () { qstat -tn1 | awk ' BEGIN { R = 0; ...
4
votes
4answers
5k views

Can IFS (Internal Field Separator) function as a single seperator for multiple consecutive delim chars?

Parsing an array using IFS with non-whites space values creates empty elements. Even using tr -s to shrink multiple delims to a single delim isn't enough. An example may explain the issue more ...
3
votes
2answers
94 views

Finding missing value in text file

I have a text file with following data. Name Feature Marry Lecturer Marry Student Marry Leader Bob Lecturer Bob Student ...
3
votes
4answers
2k views

Replacing text from a list of replacements. Added complication: backslashes

I have a file A that contains pairs of strings, one per line: \old1 \new1 \old2 \new2 ..... I would like to iterate over file A, and for each line perform the replacement (e.g. "\old1 -> \new1") ...
2
votes
3answers
2k views

Comparing text files using Bash and AWK

I have two text files, and I want to compare their corresponding values according to their rows and columns. By comparing, I mean to check if the values are equal and echo if the values are the same ...
2
votes
5answers
891 views

Why is the first line comment of .sh file necessary? [duplicate]

I was told that the first line shebang (#!/bin/bash) is necessary in the shell script file, and the file won't run accurately without this line. But I tested some scripts. They work just fine without ...
2
votes
2answers
2k views

/usr/bin/env: zsh -: No such file or directory

I get the error /usr/bin/env: zsh -: No such file or directory ...when I run an executable zsh script that starts with the following shebang line: #!/usr/bin/env zsh - Also, FWIW, replacing - ...
2
votes
2answers
93 views

Scripting to domain allocation to server

I have two text files: file #1: domain.txt cocacola.com airtel.com pepsi.com file #2: servers.txt 192.0.53.42 , 4 # 4 domains already allocated on server 192.0.53.42 192.53.1.2 , 1 # 1 ...