Tag Info

New answers tagged

0

The "Host key verification failed" is from the underlying SSH process. See pdcp(1): When using ssh for remote execution, stderr of ssh to be folded in with that of the remote command. When invoked by pdcp, it is not possible for ssh to prompt for confirmation if a host key changes, prompt for passwords if RSA keys are not configured ...


3

Don't use setuid shell scripts, the SUID bit is not honored on shell scripts anyway on current systems. Use sudo instead, as you attempted anyway: eka ALL=NOPASSWD: /home/eka/test/test.sh And then: eka$ sudo ~/test/test.sh With that, test.sh will be executed as "root". No need to use setuid here.


2

You need to store the count somewhere it will persist across multiple runs of the script, since variables are just in memory for that single run. The easiest place is probably in a file. The particular way you store it in a file depends on a few factors including how many times you're counting, and whether you expect concurrent runs. A simple robust way ...


0

I'm still looking for a pure bc answer to how to round just one value within a function, but here's a pure bash answer: #!/bin/bash echo "Insert the price you want to calculate:" read float echo "This is the price without taxes:" embiggen() { local int precision fraction="" if [ "$1" != "${1#*.}" ]; then # there is a decimal point ...


2

This should not be done by a script. You can achieve your goal by echo "options psmouse proto=imps" | sudo tee /etc/modprobe.d/psmouse.conf Do it once and your touchpad will work after reboot. But you can get your touchpad working a normal way too. If you decide to install an Elantech driver, you will have to revert this setting. It can be done by sudo ...


0

Using grep, to store e.g. WD_MANAGEGOLD_DATETIMESTAMP's value into a wd_managegold_datetimestamp variable and WD_MANAGEGOLD_SUCCESS's value into a wd_managegold_success variable: #!/bin/bash # ... wd_managegold_datetimestamp=$(< savedState.properties grep -Po '^WD_MANAGEGOLD_DATETIMESTAMP=\K.*') wd_managegold_success=$(< savedState.properties grep ...


2

You can export them like this. #!/bin/bash #Specific Set Variables SpecficStatus="Pass" #SetVariable timestamp() { date +"%a %d %b %Y %T %Z"; } SpecficDate=$(timestamp) echo $SpecficStatus echo $SpecficDate #Properties Call file="savedState.properties" #Echo out the file while IFS== read -r VAR1 VAR2 do #echo "VAR1=$VAR1 : VAR2=$VAR2" export ...


1

Instead, you could use at command. Install it with sudo apt-get install at And run sudo echo "shutdown -h now"|at now + 30 min


2

This script controls the shutdown timer using sleep and a loop. #!/bin/bash # Read Password read -s -p "Password: " password echo # Send messages for i in {0..5} do echo "Shutdown in" $((30- i * 5)) "minutes" sleep 300 done echo "Shutdown now" | wall # shutdown and screensaver Command echo "$password" | sudo -kS shutdown -h +30 & ...


1

Try this: xrandr --output eDPI1 --mode 1024x768 --pos 0x0 --rotate normal --output HDMI2 --mode 1366x768 --pos 1024x384 --rotate normal


1

I think the problem is that the script looks for Mem and Swap, whereas your localization produces Speicher and Auslagerungsdatei. Just add an LC_ALL=C before the frees in the script: export LC_ALL=C mem=$(free | awk '/Mem:/ {print $4}') swap=$(free | awk '/Swap:/ {print $3}') Or: mem=$(LC_ALL=C free | awk '/Mem:/ {print $4}') swap=$(LC_ALL=C free | awk ...


2

When you have two commands on two separate lines of a shell script, the second will only run when the first has finished. To avoid this, you need to add a & to the end of the first command to have it run in the background: #!/bin/bash sudo shutdown -h +30 & gnome-screensaver-command -a As for not asking for the password, you'll need to tell sudo ...


6

Solution to problem 1 and 2: You need to edit your /etc/sudoers (sudo visudo) file to add the relevant entry to grant the passwordless sudo permission for the user to run this script (not the shutdown command) : foo spamegg = (root) NOPASSWD: /path/to/script.sh Here foo is the username, spamegg is the hostname, replace the /path/to/script.sh ...


0

You can Block IP Address in Ubuntu using iptables I have created a DEMO video to how to block/unblock a Source IP address Block/Ublock IP Address in Ubuntu Using iptables


0

Make the script with executable permissions and copy to the location /etc/network/if-up.d/ as soon as network ethX up scripts in this location will be triggered.


0

You can put your script in /etc/rc.local. This command will be executed at the end on the start of you pc. Simple you can edit sudo nano /etc/rc.local and at the end of file put you command mavproxy.py --master=/dev/ttyACM0 --baudrate=57600 --out=myipaddress --console &&


0

It was my classpath. A friend told me about the -cp flag that could be used to define the classpath. once that was in, the JVM found main(). however now i've just got to find out why it can't find the file i'm passing in for main to work on.


0

You have to check 3 points : Nautilus / Nemo configuration : http://askubuntu.com/a/286651/301025 The script file must have executable permission : http://askubuntu.com/a/275714/301025 The file system must allow execution : Type "mount" in a console Check if your file system has noexec flag Remove noexec flag in editing /etc/fstab and remount the modified ...


0

I have one more option that is a mixture of these answers but what makes it nice is that you only need to press one key and then the script continues thanks to the -n option of read. In this example, we are prompting to shutdown, reboot, or simply exit the scrit using ANS as our variable and the user only has to press E, R, or S. I also set the default to ...


1

I have used Plop boot manager many times for installing different Linux Distros (including Ubuntu). It allows me to boot a machine for a device that is not supported by the bios. Very useful on machines that can not boot from USB.


1

In detail, if you want to install the ubuntu without flash drive and all other you have tried then you can also install it from network. If your system is older and The network installer helps you install ubuntu in graphical form See the link here


0

I think what it's asking is what is the path of your shell defined in $PATH. you can do: printenv then get the SHELL=/bin/bash replace "Path of your shell: " with whatever you get for your SHELL. In the above example your code will be: echo -n -e "/bin/bash" I'm not sure though if you need to have the double-qoute.


1

If you have Windows installed, You can directly boot (and install) from iso without burning it to DVD/CD/USB drive using EasyBCD.


2

As far as i know, there are 5 Ways to install ubuntu: 1- Boot From a Live USB Drive or CD 2- Install Ubuntu On Windows With Wubi 3- Run Ubuntu In a Virtual Machine 4- Dual-Boot Ubuntu 5- Replace Windows With Ubuntu (Read More here)


1

You can execute script with ./ if you are in same directory as script. But if you want to run it from anywhere , you have to put the script into one of the folders listed in your $PATH preferably /usr/bin or add a custom folder to the list. As for creating a file, if you specify full path to script , like nano /usr/bin/myscript.sh , yoi don't have to be ...


1

Just this command will do: gnome-terminal Normally if you want a command to open from the terminal and separate (so it returns to the prompt without having to close the opened program), you have to use something like this: gnome-terminal & disown However the parent terminal seems to detect that the same command is being used so you don't need to ...


3

You can use this modified script: #!/bin/bash # Script to add a user to Linux system if [ "$(id -u)" -eq 0 ]; then read -p "Enter username : " username read -p "Enter password : " password IFS=' ' read -a grps -p "Enter group names : " if grep "^${username}:" /etc/passwd &>/dev/null; then echo "$username exists!" ...


1

Many thanks to @Lety for pointing me where to look for the answer. Nested loops worked perfectly. #!/bin/bash outer=1 for x in *.hmm do mkdir $x.dir inner=1 for i in *.emitcons do program --different_output $i.$x.1mtblout $x $i> $i.$x.1mout rm $i.$x.1mout let "inner+=1" done for f in *.1mtblout do ...


1

A different approach is to arrange the windows form a pre- defined(customizable) grid (columns/rows) An example: rearranged into (cols set to 3, rows set to 2): rearranged into (cols set to 4, rows set to 2): The script below can be used to do that. As said, the number of columns&rows can be set, as well as the padding between the windows. The ...


2

The name of the package is gnome-terminal Here is a page with all of the switches you can use along with it http://manpages.ubuntu.com/manpages/karmic/man1/gnome-terminal.1.html


2

The script below will tile an arbitrary number of chrome or chromium windows in a Nx2 grid (N rows, 2 columns) where N depends on the number of open windows. If there is only one window, that window will be maximized (or unmaximized if it is already maximized). #!/usr/bin/env bash ################################################# # Exit if there are no ...


1

I created this function that I use in bash scripts. # Function to echo in specified color echoincolor () { case $1 in "red") tput setaf 1;; "green") tput setaf 2;; "orange") tput setaf 3;; "blue") tput setaf 4;; "purple") tput setaf 5;; "cyan") tput setaf 6;; "gray" | "grey") tput setaf 7;; ...


1

Let's start. Create load.sh script nano /path/load.sh #!/bin/bash #we use output from "uptime" i "w" to have load on 5 min UPTIME=`uptime`; W=`w`; RAM=`free -m`; DATE=`date`; sleep 3 DF=`df -h` sleep 3 echo "######################################" >> /var/log/load-result/load_log echo "$DATE" >> /var/log/load-result/load_log echo "" ...


1

If you insist on awk, you could do: $ ping -c 4 google.com | awk -F "[= ]" '$2=="bytes"{print ++c "\t" $(NF-1)/1000 }' 1 0.0361 2 0.036 3 0.0357 4 0.0363 Personally, I would do it using grep and only use awk for multiplying the milliseconds by 1000: $ ping -c4 google.com | grep -Po 'time=\K[\d.]+' | awk '{print NR,$1/1000}' 1 0.0357 2 ...


5

The main problem is that the $ is important to perl. When you use it in a system command, you need to escape it: $thirdlast=`df -H | awk '{print \$(NF-3)}'`; print $thirdlast; Otherwise, perl will try to expand $(NF-3) as a perl variable. The variable $( is the perl process's real GID: $( The real gid of this process. If you are on a machine that ...


1

I use this old script, names hilite.pl, taken from the web, already with the "unknown author" line! #!/usr/bin/perl -w ### Usage: hilite <ansi command> <target string> ### Purpose: Will read text from standard input and perform specified highlighting ### command before displaying text to standard output. ### License: GNU GPL # unknown author ...


1

Install the package inoticoming sudo apt-get install inoticoming Create wrapper script watch_output: #!/bin/bash backup_folder="$HOME/backups" filename="$1" mkdir -p "$backup_folder" if [ "$filename" == "output.txt" ] then echo "New or changed file \"output.txt\" in $2" mv "$2/$filename" "$backup_folder/${filename%.*}.$(date ...


2

If one of the strings starts with a "-" you need put "--" as the last argument BEFORE the string. This will prevent the options parser from treating the string as a command- line option. Source rpl -x'.txt' '0 ' -- '-1 ' /home/administrator/temp/myText.txt Also, is there a way to replace all the strings in the text that begin with 0 with -1? As ...


3

First install the package inotify-tools: sudo apt-get install inotify-tools A bash script would help #! /bin/bash folder=~/Desktop/abc cdate=$(date +"%Y-%m-%d-%H:%M") inotifywait -m -q -e create -r --format '%:e %w%f' $folder | while read file do mv ~/Desktop/abc/output.txt ~/Desktop/Old_abc/${cdate}-output.txt done What does this script ...


2

The script below will move and rename any file that might appear in a defined directory (dr1). It renames the files like: output_1.txt, output_2.txt` etc. The script looks "actively" if the targeted name already exists in directory 2 (not from a "blindly" chosen range), so you can start and stop the script at any time without the risk of overwriting existing ...


0

#!/bin/bash # # Author : subz # Copyright (c) 2k15 # # Make kill the tomcat process # TOMCAT_HOME=/media/subin/works/Applications/apache-tomcat-7.0.57 SHUTDOWN_WAIT=5 tomcat_pid() { echo `ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'` } start() { pid=$(tomcat_pid) if [ -n "$pid" ] then echo "Tomcat is ...


0

In addition to the good description of the vboxautostart-service above, you can do VBoxManage modifyvm server --autostop-type savestate to automatically stop the guest at shutdown. For Ubuntu 14.04 I had to add a sleep 30 to the vboxautostart-service stop section, so that it waits until guest has been saved completely.


1

For highest security, you would want to store the password in only one place, that is your mind. But this is not a option as you want to completely automate the process and this method will require you to enter the password everytime. You might have a look at hashing encrypting technology like gpg. But even here, you will need to remember and enter a ...


0

Why its not working ? To do apt-get update and apt-get upgrade you must become a sudo user. I mean your script should executed with sudo privileges. Any other stoppings ? Yes , you are not doing giving -y that let upgrade command automatically download after update. Is it a major thing ? Yes , if you dont pass -y along with command then your cron will ...


1

I suppose that you are using crontab with normal user which means that he can't update/upgrade a system without providing a sudo. Also apt-get update and apt-get upgrade will prompt user for confirmation so you have to pass this confirmation before. yes | apt-get update yes | apt-get upgrade So to solve it you have to run your commands with sudo, but ...


8

To run your script at startup simply create a new cronjob. First open crontab by: crontab -e And then add the following line to it: @reboot /path/to/your/script


3

First of all you need to comment out all the lines that are not scripts. #this is a comment sudo apt-get your command Also this will fail becaue you need a yes. sudo apt-get -y upgrade That will say yes for you. RISKY! You don't need sudo to work with xrandr. And you are never outputting your resolution. Here is an example of one of mine. xrandr ...


2

In bash, the latest backround process' PID is stored in $!: nohup <command> & pid=$! To send a process a signal you can use kill: kill -<signal> <pid> Putting the pieces toghether, to start e.g. a background watch -n1 echo foo process and send it e.g. a SIGTERM signal later: nohup watch -n1 echo foo & pid=$! # ... kill -15 ...


18

The PID of the currently running script is $$ http://www.gnu.org/software/bash/manual/bashref.html#index-_0024_0024 ($$) Expands to the process ID of the shell. In a () subshell, it expands to the process ID of the invoking shell, not the subshell.


3

Run-parts will work if your scripts have the correct names. If you don't want to deal with renaming your scripts to fit run-parts's complex naming scheme, you could do something as simple as for file in ~/target/*; do $file 2>/dev/null; done That will attempt to execute all files (and directories) found in ~/target. The 2>/dev/null redirects error ...



Top 50 recent answers are included