New answers tagged

1

Take the steps you are using to accomplish these tasks manually and incorporate them into a shell script that you then invoke at the desired times through cron - "Cron is a system daemon used to execute desired tasks (in the background) at designated times." For help with scripting itself the Linux Documentation Project has a helpful page of info to peruse. ...


2

Since that .sh extension is only a hint for users (yep linux doesnt dance in the line of doing extension yada yada like windows) your script lacks as first a shebang line, so you script should look like this: #!/bin/bash echo "start" #you might want to use explicit paths here this is why your script fails cd /home/username/GoogleDrive/ #you might want to ...


8

[ brackets are alias for test command and there is no > sign in the regular test command. Use [ $i -gt 3 ] $ for i in {1..5}; do echo $i; if [ $i -gt 3 ] ; then echo $i; fi; done 1 2 3 4 4 5 5 You could use bash's arithmetic expansion (()) as well $ for i in {1..5}; do echo $i; if (( $i>3 )) ; then echo $i; fi; done 1 2 3 4 4 5 5 You could ...


2

You have two echo commands in there the first one isn't necessary. Editing your command to this should work: for i in {1..5}; do echo $i; if [[ $i -gt 3 ]]; then echo $i; fi; done As an extra improvement, if this command will only be run in bash, It's worth using [[ instead of [. It does much the same thing but has some nice additional functionality.


0

Here is a solution you should be able to work with. It isn't pretty and takes a bit of work and may be different depending on what version of Ubuntu you are using. I came up with this using 16.04. I also just tested this to boot into a different kernel because I don't have Windows installed on this box. Since you have a dual boot I have to assume that you ...


1

Something like the following would accomplish your purpose, with 'testing' being a text files with a list of URL images: cat testing | xargs -n 1 -P 8 wget -q Works beautifully on my system! You can manipulate the -P option as the man pages describe: -P max-procs Run up to max-procs processes at a time; the default is 1. If max-procs is 0, xargs ...


0

Process /usr/sbin/dhcpd is protected by AppArmor. AppArmor prevents the process to launch other processes. You can modify the process profile in /etc/apparmor.d/usr.sbin.dhcpd. Add a line with '/home/user/script rUx,' and it should be OK. Ux enables the designated child processes to run without any AppArmor protection. Use this mode only if the child ...


1

What you want is to use getopts . Bellow is a typical template I use in my script. Usually I have a main() function and parse_args() function, and I pass arguments form one to the other. #!/bin/bash #set -x parse_args() { echo "Hello, I'm parse_args function" local OPTIND opt # OPTIND must be there, # opt can be renamed to anything # ...


0

You can do this in many many programming languages (to name a few phython, c, c++, java, etc. etc.), but lets assume you want to do a custom command in bash (the code set of your terminal), you can do this like in the following example. Lets further assume you want to create a command for backing up your files to a location you want to add as custom ...


0

Well, the file that you're putting between the quotes, to execute as a bash command, is a 15917 byte bash script (written by Somebody Else, and you're running it without inspection, but that's off topic). If you split it up into simpler commands, you could: curl -s https://install.prediction.io/install.sh >install.sh # inspect install.sh here bash ...


0

The Problem ist you edit with Dos! open your file with vi then set unix with: :set ff=unix and :wq and it all fine Have a ball DaFreder


0

I was confusing things. The /etc/cron.d/rsnapshot file came with the rsnapshot package, it was not created by the crontab command (hence, why it had a different schedule). It is not necessary to use the crontab command at all, simply edit the /etc/cron.d/rsnapshot, this works fine.


0

To proof, that crons are starting: Make a cron like @reboot touch file and find / | grep file. It will exist.


2

Good explanations here already. I just wanted to add that ideally you shouldn't use file extensions for executables. Usually you need to accomplish something relatively easy and you start with a little shell script. Over time you start adding more and more functionality to your script, until it arrives some time that it becomes unmaintainable or you need ...


0

Maybe the more efficient is to use the reboot parameter in your crontab with the line like that: @reboot /home/user/script.sh It will launch the script every time the server boot. I use that on several servers to send me a mail when it boots.


32

You're confused. The .sh extension is only a hint to humans, and has absolutely NO effect on how the system handles the file. Unix/Linux did not make the Windows' Secrets.pdf.exe blunder. Here is what happens when you type foo: Redirection for STDIN, STDOUT and STDERR are set up. The shell checks its internal hash table to see if it already knows a ...


8

Key point is this: Extensions are irrelevant in any Unix-like system system.A filename is just name and has no effect on whether or not script or compiled executable can run. A programmer may add a .sh extension to designate that a file is shell script, or .py for python script, but unlike Windows , any unix doesn't care about naming, it cares about ...


4

To run files without an extension you normaly dont need to do much, just make sure you have (in case of bash scripts) the proper shebang line at the very first line: #!/bin/bash then you aswell need tho make the file executable for the system by chmod 755 yourfilename This is the same as using chmod +x yourfilename the numbers are easy explained. It ...


1

I just found https://www.opengl.org/discussion_boards/showthread.php/157014-Compiling-with-gcc, and I modified the code to get rid of the 100% CPU hog; it seems to work fine on Ubuntu 14.04 - simply run it from a terminal, draw your rectangle area, and the program will exit, printing the coordinates in the terminal: xrectsel.c: #include<stdio.h> ...


0

put steps 1,2,3 into script1.sh put step 4 into script2.sh Then setup cron for the appropriate user to execute the scripts according to your schedule: minute (0-59), hour (0-23, 0 = midnight), day (1-31), month (1-12), weekday (0-6, 0 = Sunday), command 01 * * * * /usr/bin/directory/script1.sh 30 2 * * * /usr/bin/directory/script2.sh script1.sh ...


2

One solution could be setting up cronjobs to lock/unlock the game directory. To do so, follow the steps below. Make sure cron-daemon is installed sudo apt-get install cron Setting up the cronjob to run for root Start editing the cronjob by issuing following command: sudo crontab -e Add the folowing lines into the editor: 00 */1 * * * ...


0

glenn jackman's point is well taken. But, to solve your immediate use case, how about backticks? Like so: `echo $COMMAND` For example, this works: COMMAND='ls /' `echo $COMMAND`


-1

no no no.. your problem here is that when you sudo, your current directory is not fully realized. you just have to call your script by the full path, like this(assuming your script is in /tmp) sudo /tmp/connector.sh


0

My solution directly adapted from MarcoS' answer on StackOverflow is: & sudo -n /home/anyuser/Scripts/test-script cache_bak -- 2> sudo-stderr_"$(date+\%Y\%m\&d-\%H\%M\%S)".log EXPLANATION: The -n flag suppresses' sudo's passwd request. So nothing is displayed on stdout. If a passwd is nevertheless required, sudo dies gracefully after sending ...


2

Your script could simply consist of: #!/bin/bash echo "Files with 755 permission:" find . -perm 755 echo "Deleting all other files" find . -not -perm 755 -delete echo "Done" Note that it will delete files from the current directory and all directories beneath it. It will also delete anything with a permission other than 755 without warning, so use ...


2

This is not explicitly pointed out in the documentation (at least nowhere that I could notice), but the problem is that alias expansion takes precedence over variable expansion; that means that the $1 token is checked to see if it corresponds to an alias, discarded as a potential alias and only after that expanded as a parameter. Since there's no command ...


2

The following script should do what you want: it runs in the directory youre calling it: #!/bin/bash echo "###START###" for filename in * do if [ $(stat -c "%a" "$filename") == "755" ] then echo "Files with 755 permission: $filename" else echo "REMOVING: $filename" rm "$filename" fi done echo "###DONE###"


2

What you need to do Install xprintidle, to keep track of the current idle time (defined by lack of keyboard- and mouse events). Create a small background script (further below); copy the script into an empty file and save it as dim_keyboard.sh. Make the script executable and copy it to a location where unauthorized users cannot alter the script (e.g. ...


0

The reason why it works like this is how the shell works. First it starts to interpret everything what it can. I.e. it interprets what is in " quotes. It does not interpret what is in ' quotes. Try to compare echo "$(date)" with echo '$(date)'. If you want to do what you want you must use another approach, for instance use : awk '{ system("echo `date -d ...


2

EDIT In the original answer, further below, the countdown window appeared after an arbitrary idle time. Re- reading your question, you might want it permanently. The permanent version is below (which is simpler), the original answer further down. 1a. Version, permanently showing countdown time The solution is a background script, showing a semi- ...


1

While J. F. Sebastian's answer is probably what you are looking for, there is also a tag-based file system named tagsistant which might be worth looking into. You can treat your tags like directories in conventional file systems and browse your files by navigation. This makes it easier if you have several tags in a file and want to search and sort for them.


2

The answer lay in pursuing my inclination that a wrapper script was needed, with that script providing the means to run an interactive subshell (-i option to bash): /usr/local/bin/vim-gnome-wrap #!/bin/bash -f bash -ic 'vim "$@"' vim "$@" ... then edit /usr/share/applications/vim.desktop or copy it to a new *.desktop file, with these changes: ...


3

You could use exiftool, to get meta information from jpg, png files. To install exiftool, run: $ sudo apt-get install libimage-exiftool-perl Usage: exiftool -s example.jpg It seems the most complete info is stored as TagsList. It even supports hierarchical tags saved by Shotwell e.g., nature/sky. The tags can be also found in Subject, Keywords, ...


1

you can install a program called xprintidle to give you the idle time of the computer but you would have to come up with some sort of script to show it on the screen I'm no good at writing scripts so this is all the help I can come up with ... hope it gives you a place to start.


1

This problem has been discussed on Unix & Linux. Quite simply, there's no real way to do this. The simplest workaround is to run Vim in screen or tmux. Instead of: Exec=vim %F Have: Exec=screen vim %F Then, even if you do close the terminal, you can open another terminal and resume the session: $ pgrep screen -a 974 gnome-screensaver 7853 SCREEN ...


1

It is sufficient to have 3 commands that use find SOURCE_FOLDER -type f -exec COMMAND {} \; structure. Bellow is a script that combines all 3. Each command will exit silently if no files found - simple as that; that means if you have png files but not jpeg files , you still will move png where they need to be without errors. Here's a small demo , where you ...


0

You can use Prompty. It will allow you to prompt the user for their password, and then you can use Prompty's exit code to determine if they entered the correct password or not. If they didn't then stop your script. Installation: [Applies to Prompty 1.0] Download Prompty from one of the links posted at ...


2

I'm assuming the entire script would fail It won't, only that single command would "fail" (meaning the *.jpg globbing pattern will be expanded to a literal *.jpg, which will make the command throw an error in case a file named *.jpg doesn't exist), but the script will keep executing despite the error. So in most cases that's not a concern, however if ...


0

Use the ip command insted of ifconfig, which is deprecated. ipAddr=$( ip a s eth0 | awk '/inet.*brd/ {print $2}' ) Sample output: 172.16.2.136/16 If you don't want to include the CIDR, use this: ipAddr=$( ip a s eth0 | awk '/inet.*brd/ {print $2}' | awk -F'/' '{print $1}' ) Sample output: 172.16.2.136


0

So I like to make backups using a bash script like this DATE=date +%Y%m%d-%H%M tar -jcvf /home/backup/myfiles-$DATE.tBz2 dirtobackup1 dirtoback2 If you want you can run something like this to clean it up find /home/backup/ -ctime +2 -exec rm {} \; This has a number of advantages over what you are asking. Backups are compressed and in files. Since ...


0

I would not use ifconfig because at least on some distro's it's being replaced by ip. If you know your interface you can do this: ip addr |grep eth0 |grep inet |awk '{print $2}' It will give you the mask also which you can cut off like this ip addr |grep eth0 |grep inet |awk '{print $2}' |cut -d "/" -f 1 I'm assuming you are using bash for your ...


0

In order to get your IP Adress from Ifconfig you can use this: echo `ifconfig tun0 2>/dev/null|awk '/inet addr:/ {print $2}'|sed 's/addr://'` This command will get the IP address of tun0.


0

File Manager > Edit > Preferences > Behaviour forExecutable Text Files. In Ubuntu it is set to View Executable Files when they are opened i prefer set it to "Ask each time" like the previous version of ubuntu.


0

A simple loop in a script: #! /bin/bash start=$SECONDS while (( SECONDS - start < 3600 )) do sleep 10m pgrep -f test &>- || exit done echo success SECONDS is a special variable in bash that contains the number of seconds since the script has started. pgrep test checks for a process named test. If it doesn't find one, we exit the script. ...


1

You can use a while loop; here i am using pgrep to check if the process is running: #!/bin/bash counter=0 while :; do [ "$counter" -eq 6 ] && break if pgrep <process_name> &>/dev/null; then echo "Success !!" (( counter += 1 )) sleep 10m else echo "Process not running..exiting !!" break ...


0

pactl is more suitable to run a single command and gives better feedback. pacmd is more for “shell sessions” with the PulseAudio daemon.


0

On newer Ubuntu versions systemd is used and /ect/rc.local is not loaded always by default. Check if the Compatibility service is loaded with systemctl status rc-local.service If it contians active (exited) your setting seems fine and you could have another error in your /ect/rc.local file (this could be a command that fails for example)


1

Simply current_dir=/home/akshay/UCS source_dir=/lib/python2.7/lib-dynload/ echo "$current_dir$source_dir" And then export it export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$current_dir$source_dir


0

You must use phablet-shell command rather than adb shell. It open a console with the device too. Then, you can put enter in nano and save files.


1

Here's a small example of how that can be done form the directory you want to edit. $> ls file1.txt file2.txt file3.txt $> pwd /home/xieerqi/testing_dir $> find . -type f -printf "%f\0" | \ > while IFS="" read -d "" filename ; ...



Top 50 recent answers are included