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)

5
votes
3answers
5k views

History command inside bash script

I have been bashing my head to write a simple history script for the last two days. History is a shell-built in command I couldn't able to use that within a BASH script. So, Is there a way attain this ...
4
votes
2answers
507 views

retrieving names of all open pdf files (in evince or otherwise)

I constantly have many PDF files open. These are usually downloaded using chrome and immediately opened using evince. I sometimes want to persist the state of all my open PDF files, so I could ...
2
votes
1answer
1k views

Bash Conditional Statements

What are the three formats of conditional statements used in bash scripting?
5
votes
2answers
255 views

Collect files using find

I currently have this script: find . -name '*.log' -print0 | xargs -0 tar zcf $file To collect all the "*.log" files. I would like to modify it to include also all the ".txt" files but I don't know ...
4
votes
3answers
254 views

Best way to work through / display a tree of images sorted by size

I've got a deep directory tree containing .PNG files. I'd like to find all the .PNG files in the directory, sort them in order of size from smallest to largest, and then display every 50th image. ...
10
votes
1answer
2k views

How do I make a shell script that sends output to a process

I'm currently running a server console program in a screen because I need to both read it and occasionally send commands. I'd like to run the app as a deamon in the background (start/stop it with ...
5
votes
1answer
912 views

Batch importing .sql files

I have a bunch of .sql files in a directory that I need to import. Although I can do it manually, for scripting purposes I need to be able to apply them in bulk. How can I do that though? What ...
5
votes
3answers
11k views

Storing output of command in shell variable

I have an operation using cut that I would like to assign result to a variable var4=echo ztemp.xml |cut -f1 -d '.' I get the error: ztemp.xml is not a command The value of var4 never gets ...
17
votes
9answers
7k views

Object-oriented shell for *nix

Preface: I love bash and have no intention of starting any sort of argument or holy-war, and hopefully this is not an extremely naive question. This question is somewhat related to this post on ...
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 ...
6
votes
1answer
2k views

Reason for ksh obsoleting -eq

The latest version of ksh obsoletes using -eq within [[ ]] blocks, prefering (( )) instead. Why is this? I can't find any documentation on the advantages of (( )) over [[ ]] anywhere, and I find that ...
1
vote
0answers
854 views

Which scripting language is most widespread in system administration tasks? [closed]

I am migrating to Linux and have some experience with the Mac OS X command line/bash. I'd like to automate system admin tasks via scripting, but I am unsure as which language is the most used in the ...
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 ...
5
votes
1answer
472 views

SCO Unix run interactive script when sending a print job

I'm working with (read, "around") a proprietary ERP system on top of SCO Unix. It has several "query at print time" reports where you can assign a printer to send your job to. You usually input ...
5
votes
1answer
121 views

apt-get - How to complain on failed upgrade?

I'm trying to write a script to upgrade a bunch of remote machines and would like to verify that one package in particular is upgraded. With yum, I could say yum upgrade specific-package, and it ...
16
votes
7answers
13k views

Using xargs with input from a file

Say I have a file with the following bob john sue Now these directly corrospond to (in this case) URL pattern such as http://example.com/persons/bob.tar, john.tar, sue.tar. I would like to take ...
1
vote
2answers
284 views

Problematic build script with quotes

Hi I'm trying to create a build script that executes these commands: cd libiconv ../../src/libiconv/configure --prefix=/home/ruben/mingw64/build/gcc-libs \ ...
2
votes
4answers
4k views

Bash eval array variable name

Here is my bash case: First case, this is what I want to do "aliasing" var with myvarA: myvarA="variableA" varname="A" eval varAlias=\$"myvar"$varname echo $varAlias Second case for array variable ...
1
vote
3answers
638 views

How can I write an OpenSuse script that will change my boot menu.lst file and add “nomodeset” automatically both to failsafe and normal boot option?

How can I write an OpenSuse script that will change my boot menu.lst file and add "nomodeset" automatically both to failsafe and normal boot option? (This script is for suseStudio I'm going to write ...
5
votes
1answer
2k views

Replacing multiple lines in sed or awk [closed]

I'm trying to use sed or awk to replace 5 lines in a smb file but I just don't have any idea how to deal with the newlines.
9
votes
5answers
6k views

Run a script via cron every other week

I've done quite a bit of research in how to do this, and I see there's no direct way in cron to run a job, say, every other Thursday. Right now, I'm leaning toward making a script that will just run ...
4
votes
2answers
386 views

Scheduling command/script by specifying the exact second

I'm using bash and wondering how I can execute a command/script at a later specified time, with the accuracy of a second? I read the man page for the at-command, but as far as I could understand it's ...
8
votes
4answers
9k views

grep — removing text after delimiter token

I have a file in which I need to eliminate everything after the first ; on every line. So a file like this: sdfsdsdf; fsdfsddf;sdfsd; Will result in this: sdfsdsdf fsdfsddf I have looked into ...
4
votes
2answers
16k views

su options - running command as another user

I was wondering how to run a command as another user from a script. I have the script's owner set as root. I also have the following command being run within the script to run the command as the ...
3
votes
2answers
552 views

Block specific IP from accessing gateway

Suppose you are on linux internet gateway/router. What would you do to block a client with specific IP using bash script. I prefer something like ./block_client.sh 192.168.1.123 to block and ...
4
votes
8answers
743 views

Write a remote managing script

I need to be able to locally run a script that will connect to various servers and run commands on them. What is the best way to accomplish this?
12
votes
7answers
2k views

Practical tasks to learn shell scripting

I'm looking for some common problems in unix system administration and ways that shell scripting can solve them. Completely for self-educational purposes. Also I'd like to know how would you go about ...
2
votes
1answer
2k views

autologin console as root on fedora

Can someone help to autologin in console text mode as root in fedora, usually I can do using script like this : /sbin/autologin.sh: #!/bin/bash 0</dev/$1 1>/dev/$1 2>&1 cat /etc/issue ...
62
votes
5answers
37k views

Allow setuid on shell scripts

The setuid permission bit tells Linux to run a program with the effective user id of the owner instead of the executor: > cat setuid-test.c #include <stdio.h> #include <unistd.h> int ...
8
votes
6answers
849 views

Best way run a command on each file in a directory tree

There appear be a number of ways to do this including loops in shell script, find and xargs. Which of these is best, and which is most portable?
24
votes
7answers
6k views

What Unix commands can be used as a semaphore/lock?

I want to run multiple Bash shell scripts in parallel. However, I want to avoid race conditions. What Unix commands are truly atomic that I could use for this purpose, and how can I use them?
5
votes
1answer
300 views

What is Linux for VMS DCL “ON ERROR”?

Using VMS DCL command scripts one can catch errors by using the on error command: $ on error then goto MyErrorHandler $ directory samiam.txt $ delete x.txt $ exit $MyErrorHandler: $ print ...
2
votes
2answers
1k views

What is Linux for $DECK and $EOD?

In VMS DCL one may embed data in a command file using $DECK and $EOD. What is Linux for this?
167
votes
23answers
99k views

Repeat a Unix command every x seconds forever

There's a builtin Unix command repeat whose first argument is the number of times to repeat a command, where the command (with any arguments) is specified by the remaining arguments to repeat. For ...