Tag Info

New answers tagged

1

The command set +o lists the current settings as commands that restore the same state, e.g. $ set +o set +o allexport set -o braceexpand set -o emacs set +o errexit set +o errtrace ... You can easily restore all the options later, if you save this output to a shell variable: SAVED_OPTIONS=$(set +o) set -e # do something eval "$SAVED_OPTIONS" Bash ...


3

For the sake of completeness one have to mention Windows Scripting Host, which is available from Windows 98 and higher and is able to execute JavaScript code: CScript.exe c:\scripts\sample.js


5

Is there a way to run JavaScript without a browser, like a shell or batch script? What you are looking for are JavaScript shells. A JavaScript shell allows you to quickly test snippets of JavaScript code without having to reload a web page. They are extremely useful for developing and debugging code. Standalone JavaScript shells The ...


3

Node.js is what you're looking for. It's based on V8, the same JavaScript engine that Chrome uses. You can use it as a REPL or run scripts from .js files. Node.js's popularity in commercial projects is increasing recently. It's used for servers that have to handle many parallel connections. It's also used for development purposes, for example Bower ...


1

You do not need to do that, but you can still do it by means of checking your apparent external IP address: the following command wget 216.146.38.70:80 queries checkip.dyndns.org for your external IP. You should be able to recognize the current status of your connection that way. Alternatively, you may check your routing table: $ ip route show ...


1

You could perhaps use a combination of openvpn's: up, down, uprestart and ping-restart config file (or their corresponding command-line) directives?


0

I was having this issue with vBulletin websites about a decade ago. It seems that one of the hops in my ISP at the time would crash on a specially-crafted page, typical of vBulletin replies. After changing ISPs for unrelated reasons the issue was resolved. If your ISP is using the same networking equipment as my old ISP, then you might have the same issue. ...


1

You should use escape sequence backslash(\) inside awk command as below. Since you use the command inside double quotes the variables will be resolved before executing. So it will try to understand $4 as a system variable and try to resolve it. If you use escape sequence backslash it will retain the $4 to the awk command. iphost="$(ssh root@$machine -x ...


0

Try this in ~/.bashrc or similar export iphost="$(echo $SSH_CLIENT | awk '{print $1}')"


0

Using an environment variable may be tricky.It might be a matter of the shell you're using: some shells use $HOST, others use $HOSTNAME. I would go with the uname -n option that @grawity mentioned.


3

Use hostname or uname -n to get the kernel hostname (nodename). hostname -s will give just the first component of the same. Use hostname -f to get the FQDN – it additionally tries to translate the hostname to an IP address, then back to a domain name.


1

By "table", I assume you mean "array". With bash version 4, use the mapfile command: mapfile -t iparr < test.txt In your loop, don't forget the quotes! for ip in "${iparr[@]}"; do echo "$ip" done


0

There are plenty of resources on-line. For example: Unix Shell Scripting Tutorial Linux Shell Scripting Tutorial - A Beginner's handbook The Beginner’s Guide to Shell Scripting: The Basics


2

To unhide the files use for f in .*;do mv "$f" ${f:1}; done. Test it first just to make sure it doesn't break anything. Explanation for f in .* creates a loop of all the files starting with . to parse the . I used ${f:1} bash substring function. Thank you


2

I would change you script like so: #!/bin/sh for file in /folder/path/* do curl -u username:password -T ${file} http://www.example.com/folder/${file} done Note that the for-loop variable file is used with curl. Better way is to upload using find + curl (as was answered on SO): find /folder/path/ -name '*' -type f -exec curl -u USERNAME:PASSWORD -T ...


1

When run with a wildcard specification of ...*.txt it fails for /f %%C in ('Find /V /C "" ^< %SFTP_INDIR%\Location*.txt') do set count=%%C The above command will not work because you cannot redirect multiple files (a wildcard specification) to be the input to find. The following command will work: for /f %%C in ('Find /V /C "" ...


2

Simple. You use CTRL-C as you normally would. When you do this inside a batch script, you'll get a question ^CTerminate batch job (Y/N)? If you enter a N here, the ping ends, but the batchfile continues.


0

The solution for Google Chrome at least was a plugin by the name of "Video Speed Controller"


0

You can use -n switch of ping to specify the amount of requests to send or use Ctrl+Breakto pause to see statistics without terminating the command.


1

It looks like you're either coming to PowerShell with a strong CMD/Batch background or are trying to adapt CMD/Batch instructions/tutorials. Some of the issues you may be getting is that you're trying to use some commands as if the are being run from the command prompt rather than PowerShell. What I mean by this is, in PowerShell, dir doesn't run the ...


1

I think that could be easy with "find": export SRCDIR="/home/makgun/Desktop/Running Man" export DSTDIR="foobar" if [ -d "DSTDIR" ] || mkdir -p "$DSTDIR" find "$SRCDIR" -iname '*.mp4' -exec ffmpeg -i '{}' -c copy -metadata:s:v:0 rotate=90 copy_{} \;


1

Ok I believe I've sorted it out. I used the -Unique switch on Select to filter out repeat results. Giving the final code of: $folders = dir -s C:\Users\Name\Downloads\*.ttf | Select Directory -Unique foreach ($folder in $folders) { echo $folder } A simple solution, but I hadn't used PowerShell to script before so I wasn't aware of this particular ...


0

You can use Contains to check as you load each item into a list, or `NotContains' You can try this to get a grasp of contains: $room = @("desk","Lamp","chair","pens","Paper") $room -Contains "Lamp" $room -notContains "Whale Bladder" An easy (off the top of my head, and not tested) approximation for what you want would look something like: $FoundFiles = ...


1

This is done using a for loop. Navigate to the target directory. Then run the command below for f in *; do mv "$f" ".$f" ; done


2

This will run all executable files named savetodatabase.sh under the 2014 directory and its subdirectories, and each executable will be run within its directory. #!/usr/bin/env bash find 2014 -type f -executable -name savetodatabase.sh | while read script do cd "$(dirname "$script")" sh "$(basename "$script")" cd - done This assumes, of course, ...


2

Currently you are in fact running the scripts from the directory you have saveall in. If you want to run each of the scripts in their folders (I assume you might have some output that is logging to the pwd?) then the easiest means would likely be to cd into each of the folders and then running the individual sh scripts. So something like: #!/bin/bash cd ...


0

notepad.exe | echo > NUL What this does is, it opens notepad.exe and all of its output is redirected to the command echo > NUL. In order to redirect the whole output, the program must finish. Therefore we have to wait until notepad.exe is finished. The output goes to echo. Echo doesn't use the input in any way and just outputs something to NUL. NUL ...


1

With the second command :~$ ls macreave.sh fgvdvg > testo 2>&1 you will cause the stderr ouput of ls to be written to the same filedescriptor than stdout (2>&1) and the stdout to the file testo: so you have a unique flux that finish in your file. With the first command instead ls macreave.sh fgvdvg > testo 2> testo you are ...


1

Now that I understand your requirements then store the ip addresses in an array and reference each element iparr=($(awk '/^DN/ {print $2}' StateNodes.txt)) Show the elements in the array: echo ${iparr[@]} List the elements in the array: for e in ${iparr[@]} do echo "$e" done List the first element in the array echo ...


0

TL;DR - use bash only for installing a better language (if it isn't already available), otherwise you're wasting unrecoverable, precious human time. If you can't do it on the command line by hand without mistakes, don't script with bash/shell. It's 2015, so I'd consider the following: memory overhead Ruby/Python runtime memory overhead compared to bash ...


1

Guard - is a cross-platform robust tool for watching directories (not just files) and running commands whenever files are added, modified or deleted. It handles a mass of issues related to watching files, both OSX-specific and general file/directory watching problems. It's also simple to setup and get running, and it uses the Listen library for watching ...


1

Your script should work more or less as intended (it does here): [Hostname: ] g-4.n.g.fr-w1 [Before concat] g-4.n.g.fr-w1 [After concat] g-4.n.g.fr-w1.v.1 if that doesn't work, try: printf "%s.v.1" "$worker" I would suggest modifying your script to make it clear that you are using grep to search for a string in the file, and removing plain echo $vars ...


3

$(command) is “command substitution”.  As you seem to understand, it runs the command, captures its output, and inserts that into the command line that contains the $(…); e.g., $ ls -ld $(date +%B).txt -rwxr-xr-x 1 Noob Noob 867 Jul 2 11:09 July.txt ${parameter} is “parameter substitution”.  A lot of information can be found in the shell’s man page, ...


3

In your example, $var and ${var} are identical. However, curly braces are useful when you wish to expand the variable in a string: $ string=foo $ echo ${string}bar foobar $ echo $stringbar $ Thus the curly braces provide a means of substituting the variable in order to get the name of new variable, itself to be substituted.


2

I usually see it more commonly in strings. Something like this will not work: var="a" echo "$varRAW_STRING" But this will: var="a" echo "${var}RAW_STRING" As you correctly said, $() is used to execute a command: dir_contents=$(ls) You can also use backticks, but I find the $() more versatile. For one thing, backticks cannot be (easily) nested. ...


0

Try echo password|runas /user:test "cmd"


2

As noted, you should correct the $File typo. Depending on what you do with the output, you may not need the if test at all. You say you would like the IP address stored in a variable: file=$1 echo $file ip=$(grep -e DN $1 | awk '{ print $2; }') echo $ip This can be simplified a lot further for what it's worth, but it matches what you have already. Note ...


2

Doesn't really answer my question of why, but I did find a satisfactory workaround: I created a shortcut (right click on a blank area in a Windows Explorer window -> New -> Shortcut) and set the target of the shortcut to be my script. Once that shortcut is in a folder that's on my path, I can call my script with just the name of the shortcut (without any ...


1

Not an answer, and you likely already thought of this as a solution so this is really for others, but using a one line .bat file to call the python script works fine. And you can, of course, name the bat file "myscript.bat" and it will work without the .bat extension.



Top 50 recent answers are included