Tag Info

New answers tagged

1

Loops are run as a separate process so variables inside a loop are destroyed when the loop ends. If you can use Python, it does keep variable changes inside loops. currd = ["dir1"] is_this = "n" datalines = ["dir1"] print is_this # checking variable for lines in datalines: if lines != "".join(currd): print lines + " is not current dir" ...


0

Call /etc/mongrel.sh from /etc/rc.local. This script called rc.local is executed after all the normal system services are started, at the end of the process of switching to a multiuser runlevel, so you might use it to start your service,


0

You can add your script in cron job. To add the script in cron job follow below steps Open terminal with root access. Run crontab -e this command will allow you to edit your cron. Add the line @reboot sh /etc/mongrel.sh The above process will execute that script once your computer boots up.


0

| while read kk; do echo "xdotool keydown $kk && xdotool keyup $kk &&"; done; echo true Note the pipe in front; this goes on the end of whatever OP uses to generate the xev output described


0

exec The command it runs, su, replaces the shell without creating a new process. sudo -s /bin/sh -c The substitute user runs the specified shell, /bin/sh and executes the following command. exec "$0" "$@" Run command $0 , the name of the script, (your first variable, i.e., /opt/nsq/bin/nsqd ) "$@" with all the arguments, using the appropriate ...


7

This script does not use polling. In other words, it does not do periodic checks. Instead, it uses a tool, inotifywait, that is designed to monitor changes to the filesystem. In this script, inotifywait monitors the current directory (.). Every time that a file is created in that directory, inotifywait emits its name and the script checks to see if it ...


0

until [ -f /tmp/examplefile.txt ] do sleep 5 done echo "File found" exit Every 5 seconds it will wake up and look for the file. When the file appears, it will drop out of the loop, tell you it found the file and exit (not required, but tidy.) Put that into a script and start it as script & That will run it in the background. There may be ...


6

Parsing ls is not a good idea. Instead, you can use the -e test to check if a file exists: #!/bin/sh until [ -e sleep.txt ]; do echo "sleep.txt doesn't exist as of yet..." sleep 1 done echo "sleep.txt now exists!!!" sleep 2 Consult man test for more informations about test command.


18

Looking at whether or not the system has a battery is not reliable - a UPS connected to the system (not just for power, but over USB as well for automatic shutdown and battery monitoring) may show up as a battery. There is a nice reliable way however: dmidecode --string chassis-type On a laptop, this will return one of "Laptop", "Notebook" "Portable", or ...


7

I'd check if the computer has a battery installed. And the following is one way to test: if [ -d /proc/acpi/battery/BAT* ]; then echo has a battery fi


8

Debian Solution: To find whether a machine running Debian is a laptop, try: [ -d /sys/module/battery ] && echo "Yes it's a laptop" This approach does not require root privileges. On other distributions, however, this directory seems to exist, at least in skeleton form, regardless of whether or not there is a battery. From the comments (below), ...


1

IMHO It's not a good idea (see below). The following command will remove the offending key of your host from the known_hosts ssh-keygen -R <host> e.g. ssh-keygen -R my_old_client Why this is not a good idea can be argued from man ssh (searching down you can read): Additionally, the server must be able to verify the client's host key (see ...


1

--fail, as mentioned in the man page, seems to do the job: $ curl --fail --location http://google.com/nope $ echo $? 22


0

Just to add to CoverosGene's answer, here is a way to list just the directory names: for f in */; do echo "Directory -> $f" done


1

if {[file exists $fileName] } will check whether the file exists on the local system (the one where expect is running), but the conditionally created file will be on the remote host (the one that the script logs into with ssh) if it exists.  Also, filename is dummy, but the conditionally created file is dummy.txt.


0

Below is an AWK flavor. awk 'BEGIN {lc=0}; /dis/ {lc+=1}; END {if (lc > 0) print lc > "test.txt"}' filename This will create "test.txt" only if there is at least one match found.


1

This will only create test.txt if the line count is non-zero: grep 'dis' filename | wc -l | { read line; [ "$line" != "0" ] && echo "$line"> test.txt; }


0

A shot in the dark: please edit your question clicking on this link because so it's really difficult to understand. In general is seems that somewhere in a script (or in a subscript) a variable is not set with a filename. You can notice from '' without a name inside in your error message cannot open '' for reading: No such file or directory You can ...


0

If you want the PID of the process running in screen, I answered that in another question on this Stack Overflow. Here is the contents of that answer: You can get the PID of the screen sessions here like so: $ screen -ls There are screens on: 1934.foo_Server (01/25/15 15:26:01) (Detached) 1876.foo_Webserver (01/25/15 ...


0

curl is not friendly with GLOBIGNORE. But, may I ask, what are you trying to achieve anyway with your curl command? If you're trying to use the asterisk to get all matching files under a remote directory (such as curl "http://www.example.com/*"), then that's not going to work anyway. curl cannot list files under a remote directory or make the webserver ...


2

You may have to tell perl that the script contains UTF-8 characters: perl -Mutf8 -pi -e 's/Ç/|/g' diff_new_old.dat see http://perldoc.perl.org/utf8.html



Top 50 recent answers are included