Tag Info

Hot answers tagged

11

Your friend on another computer probably uses an OS which has /bin/sh linked to /bin/bash. In Ubuntu (actually, Debian and most Debian derivatives), /bin/sh is not linked to /bin/bash, but to /bin/dash, which doesn't support many bash-specific features, but is considerably faster. On Arch Linux: $ ls -l /bin/sh lrwxrwxrwx 1 root root 4 Sep 28 15:26 /bin/sh ...


8

Assuming you know or can guess the end of the range, you could use brace expansions: rm a_{000750..000850} The above will delete the 100 files between a_000750 and a_000850 inclusive. If you have too many files for that, use find: find . -name 'a_*' | while read file; do [ "${file#./a_}" -gt 000749 ] && rm -v "$file" done Here, the find ...


4

Below a python solution (script). The script uses the imghdr module to recognize the file type. It will add the correct file extensions (if missing), of the following types: rgb, gif, pbm, pgm, ppm, tiff, rast, xbm, jpeg, bmp, png If the file already has a file extension, it will be skipped. In case the file is of an unknown file type (if it is damaged ...


3

To edit: Use any editor you like: gedit some_file.sh nano some_file.sh vim some_file.sh # ... To run: Either make it executable and run it giving the path: chmod +x some_file.sh ./some_file.sh Or tell bash to run it: bash some_file.sh Also see: How can I run this sh script without typing the full path?


2

Creating your crontab file with crontab -e is probably the best method for you, but starting your crontab lines with the # character tells the system to ignore those lines. Remove the # and leading whitespace before the 30 in your crontab line. Should just look like this: 30 * * * * /home/michael/Documents/example.sh Additionally, please ensure that cron ...


2

Some points that seem to be confusing you: # is the comment character. Adding it to the beginning of a line makes cron ignore that line. Don't mess with /etc/cron/hourly etc. There's no need to and they have a different format (see next point). The format of a user's crontab is minute hour day-of-month month day-of-week command The format of the files ...


2

You can define a simple task job that start on event of your choice, run your script and at the end emit event to start the other two job. For example: # mainJob - # # This service emit myEvent to run firstJob description "emit myEvent to run firstJob" start on runlevel [2345] task console log script echo "(startTask) $UPSTART_JOB -- ...


2

I believe I have an answer to my own question that leverages CameronNemo's partial solution and Mark Russell's answer to a related but somewhat different question. Two Upstart configuration files are required. The first is a job that starts as soon as the local filesystem is available, performs the desired file modifications as a pre-start script, and then ...


2

You're not using the $i variable inside the loop for i in "${addresses[@]}"; do # ..^ echo $addresses, disable, , , >import.csv # .......^^^ should be: echo $i, ... done For an array variable, when you print the variable without specifying an index, bash seems to give you just the first element. $ x=( one two three ) $ echo $x one


2

git push and git pull change your files only when there are differences. if you try to git add --all when there's no changes, it won't add anything, the subsequent git commit -m "" and git push will have no effect also. the script you referred should work properly. if you want extra checks you can do git remote update then git diff to see the difference ...


2

Move if you only need it in the target path, copy if you need it in both locations. There's no inherent "insecurity" to mv or cp, and you'll be needlessly adding complexity (and extremely likely bugs) to your scripts if you start trying to implement your own mv. For special cases there may be more suitable tools than either. For example, if you want to ...


2

You could do something like this: find . -regextype posix-extended -iregex './a_[0-9]{6}' -execdir bash -c '[[ ${1##./a_} > 000750 ]] && echo $1' "removing: " {} \; Or: find . -regextype posix-extended -iregex './a_[0-9]{6}' | sort | sed '0,/000750/d' | xargs echo The first method assumes a fixed prefix, strips it off and checks the value. ...


2

With a loop and some bash string manipulations while read -rd $'\0' f; do d="${f%/*}"; p="${d/\//_}"; echo mv -- "$f" "${d}/${p}_${f##*/}" done < <(find -type f -name '*.jpeg' -printf '%P\0') (remove the echo once you've confirmed it matches the files correctly) With the perl-based rename command and bash globstar shopt -s globstar rename -nv ...


2

The Problem Using sudo inside a script often doesn't do what you expect (see Digital Chris' link: “How do I run this sudo command inside a script?”). Sending sudo to the background will not work (correctly and reliably), if you need to provide a password. The Solution Retrieve the process ID inside the process spawned by sudo. If you use exec, you don't ...


2

I think the functions you are looking for are sourced from /lib/lsb/init-functions, and named log_success_msg and log_failure_msg: $ . /lib/lsb/init-functions $ log_success_msg foo * foo $ log_failure_msg foo * foo In this output, the first * is grey, the second is red (error case). Not extremely colorful, just enoug to get the point across... From ...


2

You could use the functions provided by the lsb-base package in /lib/lsb/init-functions. I have seen init.d scripts sourcing that file and then using the functions within, such as log_end_msg: $ (. /lib/lsb/init-functions; log_end_msg 1) ...fail! $ (. /lib/lsb/init-functions; log_end_msg 0) ...done. For example, a snippet from /etc/init.d/ssh (case ...


2

Use full path of your parent directory(in my case apps directory located in my home directory) and remove one extra command(cd ..) for f in ~/apps/*; do [ -d $f ] && cd "$f" && echo Entering into $f and installing packages done; See screenshot: with cd .. command and using apps/* See screenshot: without cd .. command and using ...


2

Simply create a .desktop file and save it in ~/.local/share/applications. In its most basic form: [Desktop Entry] Name=name_of_your_script_like_you_see_it_in_Dash Exec=sh /path/to/script.sh Icon=/path/to/some/icon Type=Application Copy it into an empty file, save it as script.desktop in ~/.local/share/applications. After log out /in, it will appear in ...


2

A one-liner using the rename command: rename 's/.*/use File::MimeInfo::Magic qw#mimetype extensions#; sprintf("%s.%s", $&, extensions(mimetype($&)))/e' * -vn it's using the Perl File::MimeInfo module to query the file (sort of how the file command does) to work out what the file is and then to append the first extension MimeInfo has for that MIME ...


1

To find which commands bash runs on start-up and which file those commands came from, run: PS4='+$BASH_SOURCE> ' BASH_XTRACEFD=7 bash -xl 7>&2 The output is lengthy but the source of the gibberish will hopefully be clear. Explanation: PS4='+$BASH_SOURCE> ' When creating an execution trace, bash will prepend every line with an expansion of ...


1

Simple script #!/bin/bash for file in ~/path/to/images/*; do TYPE=$(file --mime-type -b "$file" | cut -f2 -d/); if [[ ! $file =~ \.$TYPE ]]; then echo mv -v "$file" "$file.$TYPE"; fi done Explanation of TYPE=$(file --mime-type -b "$file" | cut -f2 -d/); (finding file type) find the extension of each $file using file(determine file ...


1

You can use find along with exec for this propose. Your install.sh should be #!/bin/bash find ./apps -type d -exec echo Entering into {} and installing packages \; replace text after -exec with your command for example #!/bin/bash find ./apps -type d -exec touch {}/test.txt \; It will loop through app and all its sub-directories and will create ...


1

cp: cannot stat ‘/GNI’: No such file or directory That's because of the whitespace: cp reads it like this: cp -ra /home/michael/Documents/GeneralNetwork /GNI That the folder: /home/michael/Documents/GeneralNetwork needs to be copied to /GNI. But there is no folder in /GNI, therefore the error. If there is a whitespace between files, put it ...


1

The installation instructions aren't telling you to run run bin/jason.sh. They're saying to run bin/jason.sh. Suppose you wanted to put the Jason folder in your home folder: cd # changes to your home folder # change URL for different version or different mirror wget http://superb-dca3.dl.sourceforge.net/project/jason/jason/version%201.4.1/Jason-1.4.1.tgz ...


1

start on starting jobA or starting jobB instance $JOB pre-start exec /path/to/script The starting bit prevents the jobs from moving on in their life cycle until this job completes. The instance bit is so that both starting events (for jobA and jobB) are inhibited, not just one, as would be the case if you did not have an instance stanza. THe use of ...


1

The script I used is as below: #!/bin/bash ts=`date +%s` ffmpeg -f video4linux2 -s vga -i /dev/video0 -vframes 3 Downloads/grab-$ts.%01d.jpg exit 0 #important - has to exit with status 0 Some search suggested using avconv, so I replaced the ffmpeg with avconv and the script worked as before. avconv -f video4linux2 -s vga -i /dev/video0 -vframes 3 ...


1

Create a simple file changeName.sh as follow: #!/bin/bash fileName=$(basename $1) filepath=$(dirname $1) secondDir=$(basename $filepath) firstDir=$(basename $(dirname $filepath)) parentDir=$(basename $(dirname $(dirname $filepath))) mv $1 $filepath/${parentDir}_${firstDir}_${secondDir}_$fileName save it, for example in ...


1

thanks for the solution! I managed to use the scripts provided here to fix my problem. Since I had to modify them a bit, here I join the improved version. The reason the original scripts didn't work for me is because some applications can have several instances, i.e. several PID, but maybe only one of them is producing sound, and is thus actually connected ...


1

Try commenting out all your "exit" commands (if any) in your script by placing # in front of them and give it a go. Perhaps you are executing "exit" in your shell that closes the terminal session.


1

This works for me: echo DRIVES=\'`cd /dev; ls sd?; cd`\' It simply goes into the /dev-directory and outputs everything with sd and one more character. After that, it returns to home.



Only top voted, non community-wiki answers of a minimum length are eligible