An automated series of instructions carried out in a specific order, such as a Windows script created to launch a specific program on startup.
Questions tagged [script]
2549 questions
580
votes
40 answers
How to execute a command whenever a file changes?
I want a quick and simple way to execute a command whenever a file changes. I want something very simple, something I will leave running on a terminal and close it whenever I'm finished working with that file.
Currently, I'm using this:
while read;…
Denilson Sá Maia
- 11,713
- 11
- 37
- 42
414
votes
7 answers
What is the difference between executing a Bash script vs sourcing it?
What is the difference between executing a Bash script like A and sourcing a Bash script like B?
A
> ./myscript
B
> source myscript
Scottie T
- 4,341
- 3
- 17
- 10
197
votes
4 answers
Linux Bash Script, Single Command But Multiple Lines?
I have the following script I wrote by searching Google, and it backs up my Linux system to an archive:
#!/bin/bash
# init
DATE=$(date +20%y%m%d)
tar -cvpzf /share/Recovery/Snapshots/$HOSTNAME_$DATE.tar.gz --exclude=/proc --exclude=/lost+found…
Jay LaCroix
- 1,991
- 2
- 12
- 4
152
votes
21 answers
Add directory to $PATH if it's not already there
Has anybody written a bash function to add a directory to $PATH only if it's not already there?
I typically add to PATH using something like:
export PATH=/usr/local/mysql/bin:$PATH
If I construct my PATH in .bash_profile, then it's not read unless…
Doug Harris
- 25,888
- 16
- 76
- 105
150
votes
7 answers
How to execute a command in screen and detach?
How can I get screen to execute a command and then detach (That is, automatically in a single script without further input beyond initially starting the script)? e.g. I run myscript.sh and it automatically starts a screen session, executes a…
darkfeline
- 1,783
- 2
- 12
- 14
89
votes
16 answers
Delete all files from a folder and its sub folders
I want to remove all files from a folder structure, so I'm left with an empty folder structure.
Can this be achieved in either batch or VBScript scripting?
I have tried a very basic batch command, but this required the user to allow the deletion of…
BobJim
- 1,290
- 4
- 14
- 24
83
votes
11 answers
When to use Bash and when to use Perl/Python/Ruby?
We are doing all our scripting with Bash so far, but I'm starting to feel a bit silly about it. While we can of course do everything we want with Bash (it's quite powerful), I'm starting to wonder if we shouldn't use a proper scripting language (in…
futlib
- 1,179
- 2
- 10
- 12
76
votes
10 answers
How can I get a script to run every day on Mac OS X?
Cron? Launchd? iCal??
If so, how?
Paul D. Waite
- 5,944
- 11
- 47
- 72
75
votes
10 answers
How can I run an application with command line arguments in Mac OS
Is there any easy way to append command line arguments to an application on a Mac? For example, to run Opera in kiosk mode or to use a different profile in Firefox, I can type
$ /Applications/Opera.app/Contents/MacOS/Opera -kioskmode
$…
Andrew
- 2,159
- 5
- 25
- 28
72
votes
6 answers
How do I perform commands in another folder, without repeating the folder path?
Is there a clever way to do copy and move operations or a command to duplicate a file, without having to do a cd, then mv after, at the same folder?
For example, I have to run the following:
mv /folder1/folder2/folder3/file.txt…
Valter Silva
- 1,371
- 7
- 23
- 32
66
votes
8 answers
Determine if command is recognized in a batch file
I'm writing a bat script in which I invoke a program (such as javac). For simplicity, I want to check if the command exists before I run it. i.e. If the command exists in PATH.
For example,
if (my_command.exe is a recognized command) then (
…
user46097
- 691
- 1
- 5
- 6
65
votes
5 answers
Remotely run script on Unix, get output locally?
I need to run a (Tcl, or whatever) script on a remote Unix machine, from a (local) Windows command shell, and I want the stdout/stderr of the script to show up in the Windows CLI. The exit code would also be useful.
Is this possible using ssh…
Cristian Diaconescu
- 3,490
- 8
- 27
- 34
62
votes
4 answers
How to launch a command on network connection/disconnection?
I have a wifi connection that requires to authenticate using a web form once the wireless link is established.
I know how to automate the authentication with a script that uses curl/curlIE.
But how can I ask Windows to call my script every time I…
dolmen
- 1,175
- 1
- 10
- 16
61
votes
5 answers
Looping Through Subdirectories and Running a Command in Each
I have a set of repositories sorted into directories based on their VCS (Git, Mercurial, SVN). With Subversion I was able to run svn update * in the parent directory and it would loop through each directory and update each repository as expected.…
Bryan Veloso
- 713
- 1
- 6
- 6
51
votes
2 answers
How to get filename only without path in windows command line?
for /r %f in (*) do echo %f
Gives the output filename along with the entire path
\path\to\dir\
How do i get just the without the path included? I need to use that 'filename' string.
Also, is it possible to do the following,…
Jay
- 1,248
- 6
- 17
- 24