New answers tagged

0

I think your best bit would be to wrap the entire script, using shc (Bash script compiler). That way you could use plain text, like echo password | sudo -S script.sh in your script. I suppose someone could decompile, but we're pretty far out there, and then if that's the concern, don't store your sudo password. Link to SHC. shc github


0

Simple way may be also just to run System Monitor (if started from Terminal you must write gnome-system-monitor) and under "Processes" tab arrange the running processes by Name and than count the number of occurrences of Bash in the listing (they will be all together if you arrange by name, so it's easy to count). Note that you must look for Bash and not ...


1

This can be done using VirtualBox Command Line Management Interface. Just run the following script at start up. #!/bin/bash VMUSER="vmuser" VMNAME="RedHatVM" #also you can put UUID in this variable (VMNAME="4ec6acc1-a232-566d-a040-6bc4aadc19a6") case "$1" in start) echo "===Starting VirtualBox VM===" sudo -H -u $VMUSER VBoxManage ...


0

The answer I believe is in this site: http://ubuntuforums.org/showthread.php?t=1726874 basically on the server you will have a directory that you place the PDF files in after they are scanned, and on a regular basis using cron, they will be printed. How often you set the cron job to run will determine how long after the file is placed in the folder it ...


1

It seems to run on startup. It shows me when I run after a reboot: sudo service rng-tools status The following: ● rng-tools.service Loaded: loaded (/etc/init.d/rng-tools; bad; vendor preset: enabled) Active: active (exited) since Do 2016-05-26 20:17:21 CEST; 22min ago Docs: man:systemd-sysv-generator(8) Process: 1599 ...


2

Fortunately, Dropbox recently expanded their CLI capabilities to include sharelinks etc. To integrate Dropbox into Thunar do the following: Initial Setup Create a ~/bin directory in your home folder if not already created. Download the Dropbox python script. Rename it as just dropbox. (The extension is not needed.) Make it executable chmod +x ...


1

You can use process substitution, so that use would look like: use() { . <(. ./hello_world.sh; declare -f "$@") } Side note: declare is not POSIX, /bin/sh may not support it, so use.sh shouldn't have /bin/sh in the shebang. (Not that it matters much, since use.sh is sourced instead of executed.)


0

Yes, it is possible. Make two files, let's call the first one main.sh and the second one sub.sh. In main.sh put the following lines: #!/bin/bash gnome-terminal -x "./sub.sh" In sub.sh put the code you want to execute. Be sure to make both files executable. Then double-click main.sh.


0

you must create a file using your favourite text editor in the following fashion #!/bin/bash your commands here The first line (I believe it is called magic line) ensures that the following commands are executed in the shell. After creating this file you have to give it executable permission: right click on file -> properties -> permissions -> tick the ...


1

One simple way would be to set an array with the four values you want to cycle through, and then use the % (modulo) operator in your for loop to determine which of the four values to assign to arr[$a] For example: #!/bin/bash values=("apple", "banana", "orange", "grape") ##################################### for((a=0;a<=100;a++)) do ...


-1

your shell script has a alot problem, i rewrite that for you. #!/bin/bash echo -en "Enter name of website ?" read name echo -e "\e[93mScanning...\e[0m" nmap $name # software Scan echo "############################################" echo "Do you wish to do Software Version scan?" read ans if [ "$ans" = "yes" ] || [ "$ans" = "YES" ] then echo ...


2

Background script to check for new screens Once per 5 seconds, the background script below looks for new screens to be connected. If that happens, it tries to set the resolution to what you set in the head section of the script (see: How to use). A notification shows if the creen was successfully set: If the command to set the resolution fails, it ...


1

I created a script for one of my monitors and run it as I connect the monitor. So you can make similar different scripts for your different monitor types and run each as per requirement. #!/bin/bash sudo xrandr --addmode VGA-0 1440x900_60.00 sudo xrandr --newmode Modeline "1440x900_60.00" 106.47 1440 1520 1672 1904 900 901 904 932 -HSync +Vsync ...


1

I constructed a couple of desktop shortcuts to achieve this sort of thing on my laptop. They are $ cat LowRes.desktop #!/usr/bin/env xdg-open [Desktop Entry] Version=1.0 Type=Application Terminal=false Icon[en_GB]=gnome-panel-launcher Name[en_GB]=LowRes Exec=xrandr -s 8 Comment[en_GB]=1368x768 Name=LowResDisplay Comment=1368x768 Icon=gnome-panel-launcher ...


0

if you simply want to check whether there is any under process then go to that directory and type ll -tr if you see .csv or .work etc at the end of the file then it means under process else not.


-1

if you want to check all processes then use 'top' if you want to know processes run by java then use ps -ef | grep java if other process then just use ps -ef | grep xyz or simply /etc/init.d xyz status if through any code like .sh then ./xyz.sh status


6

you could use find and shuf: #!/bin/bash SOURCE="path/to/source" DESTINATION="path/to/destination" COUNT=25 rm -r "${DESTINATION}/"* find "$SOURCE" -mindepth 2 -maxdepth 2 -type d|shuf -n $COUNT|xargs -d'\n' -I{} cp -r "{}" "$DESTINATION"


8

The script below should do the job: #!/usr/bin/env python3 import random import os import subprocess import shutil # set the desired number of folders to pick below n_selection = 5 # set the name of the flash drive below flashdr = "Lexar" # set the source directory (with media folders) below sourcedr = "/path/to/mediafiles" # --- try: targetdr = ...


1

I made a script with Python: The script, at GitHub Gist. (Download) Usage: python3 RandomCopier.py [source folder] [destination folder] [number to copy] The copy method: NOTE: It will not copy any files directly in the source folder, only those in sub-folders of it. Say, the source folder, src is: src |- a | |- file_a | |- file_a_2 | |- b | |- ...


2

You can do in your script or in your terminal: gnome-shell -r & disown This will start the program in background from the terminal and disowns the task then. NOTE: The disown command has to come directly behind the command which starts something in background, otherwise it will not work. Or if you already have started the program you want to detach ...


0

"No MTA installed" means that in your script, you might want to send an email, but no MTA (Mail Transfer Agent) have been specified. The cron daemon tries in fact to send outputs to you. You can install an MTA (like postfix), or, if outputs are not important, redirect to" /dev/null 2>&1"


1

First, make sure myscript.py is executable by doing chmod +x myscript.py. Second, ensure that the shebang #!/usr/bin/env python appears as the first line of myscript.py. You then execute the script using ./myscript.py [arguments].


0

Edit your script so your first line is a shebang pointing to the desired interpreter's executable path. First, find where the python executable is, with which python. Then, in your script's first line, add #!/path/to/python Then run mkdir $HOME/bin And put your script there. That should do it!


1

Add #!/usr/bin/python to the first line of your script. This presumes that you have python installed and runnable from /usr/bin, and that the current directory (.) is in your PATH environment variable (not the default,but you can change it in your home .profile file).


0

Since systemd the proper location for this is /lib/systemd/system-sleep. Make there a file eg. 999_thaw_flash and paste like this : #!/bin/sh case $1/$2 in post/suspend) your_srcipt_here .... ;; esac


0

I was using bash.bashrc because I wanted the setup process to be system wide, so putting it in ~/.profile, as Anthony suggested, was not the best solution for me. Additionally the setup script was located on an NFS, so I made symbolic link in /etc/profile.d that pointed to the location of the setup script on the NFS. Works great now!


5

If you really need to get the number of terminal you have open, go for counting the files owned by you under /dev/pts (although this might include ones opened by background processes, not by graphical terminal emulators). Alternatively, count the number of child processes of your terminal emulator(s), as shown by Jacob in the first line of his response. ...


1

You should set the environment variables in your ~/.profile. This file is sourced by display managers such as LightDM which start the X server and the rest of the graphical system. It’s also sourced by Bash (as long as ~/.bash_profile doesn’t exist) – and other POSIX shells – for non-graphical, i.e., network and console logins. The Ubuntu Wiki has lots of ...


1

This is basically because you lack JDK. This can be found by running the following command in the terminal: cd /android-studio/bin ./studio.sh So after you configured Java you'll be able to run it.


1

An awk way: who | awk 'BEGIN{count=0}{ if(NR!=1){count++} }END{print count}' Explanation: In above 1 liner command, awk is used to find the count of terminal. Inside awk program, it is just checking the number of lines return by who command - 1.


5

In a single user situation, if we take the example of xterm, we can simply count the number of pids of xterm; xterm creates a separate pid for each and every window. gnome-terminal however runs a single pid, but the good news is that it creates a child process for each and every window and/or tab. we can retrieve these child processes by the command: pgrep ...


14

Every opened "pseudo-terminal" (or "terminal emulator") have a special file in /dev/pts/ for each of it's windows/tabs and those files/numbers auto-increments, gets freed and are re-used. This simple script is using exactly those numbers to select a color from static configuration table. Append it to your ~/.bashrc: # custom color selector config=( 1 # ...


2

Tweaked @Jacob's script a little. First, using dconf watch / and switching hotcorners on/off in unity-tweak-tool to find out which variables(?) are being changed I have windows spread bound to bottom left corner, setting is in /org/compiz/profiles/unity/plugins/expo/expo-edge Also have workspace spread in bottom right corner, setting is in ...


0

I wrote myself a little script using the fdisk command, based on what I know plus bits of code found online, which does something very similar, namely, interactively format a drive into one or more partitions, asking if this is the correct drive, waiting for a set time, or input from the user, warning it is about to erase it, etc. One thing it cannot do, in ...


6

If you just want the script, skip the explanation Explanation You'll have to learn at least an appropriate programming (/scripting) language, but then: Introduction; dconf and gsettings Most (if not all) of the settings, edited by Unity Tweak Tool edit the dconf database, in which many settings are stored. Editing the dconf database is best done via ...


0

Creating an .sh (same as .exe in Windows) file would do. You can make it executable by this command: chmod +x nameofscript.sh You may have a look at this one as well which elaborates a bit more.


1

I did something like this to find files that may contain spaces. IFS=$'\n' for FILE in `/usr/bin/find $DST/shared -name *.nsf | grep -v bookmark.nsf | grep -v names.nsf`; do file $FILE | tee -a $LOG done Worked like a charm :)


2

To get the current working directory as a variable: echo $PWD (capitals), or use the command pwd Then, using the variable, the line should be: echo "This directory is called '$PWD'" Output: This directory is called /home/jacob


1

You have to use echo "This directory is called $(pwd)" What you are trying to do is called command substitution. This used to be done using backticks (` `), but the currently recommended way is using $(). You can find a detailed explanation in this wiki page.


1

As first make sure you have ffmpeg and libav-tools installed, this you can do by typing in terminal (ctrl+alt+t): apt-cache policy ffmpeg libav-tools This should get you an output like the following if both are installed: ffmpeg: Installed: 7:2.8.6-1ubuntu2 Candidate: 7:2.8.6-1ubuntu2 Version table: *** 7:2.8.6-1ubuntu2 500 500 ...


0

You might want to end your lines with && so the script only advances when the command is done. Example: ssh -t -t $USER@$REMOTE <<'ENDSSH' sudo apt-get update && sudo apt-get install -y nodejs && sudo apt-get install -y npm ENDSSH


0

So the script copying from the windows server to your ubuntu server's encrypted home (with eCryptfs right?) works OK, while you're logged in I'm assuming. Then later when you're not logged in, another script can not access your encrypted home. That's by design, nothing is supposed to be able to access your encrypted home unless you're logged in. You could ...


0

I used eval to execute the command and: var=$(${commands["$s"]}) got changed to var=$(${commands["$pattern"]}) because I was refering the file content instead of the actual pattern.


0

You can add a program or script to the /etc/rc.local file. This script is run at boot time. All the lines in the script are run as root. If you have a program named /usr/local/bin/myprogram and added this line to the rc.local script it would be run as root. /etc/rc.local: # By default this script does nothing /usr/local/bin/myprogram


0

i had some similar problem in rc.local not executing at startup sshades provided me with the following answer : Ubuntu is now using systemd, and rc.local is now considered a service which is turned "off" by default. You can turn rc.local "on" by entering the following command and rebooting: sudo systemctl enable rc-local.service ...


0

I don't have the rep to comment directly on Jacob Vlijm's excellent post, but I modified the script to permit starting an application with arguments (necessary to use setwindow with gedit --new-window). Change: if app in p and w[2] in p] for w in ws2] to: if app.split()[0] in p and w[2] in p] for w in ws2]


7

I created a script addressing your requirements: #!/bin/sh # To check internet access after booting ping -c 4 8.8.8.8 status=$? if [ $status -eq 1 -o $status -eq 2 ] then zenity --warning --text='<span foreground="red" font="15">Unable to establish Internet connection</span>' --title="Connection status" fi Save this as con_status.sh file ...


1

In Ubuntu, you can use Startup Applications (Press Super/Windows key and type Startup Applications) Create a shell script with your necessary code to check the internet To display message to the user, I would suggest you use notify-sendsince its non-intrusive and simple. Take a look at this notify-send tutorial Make your script executable chmod a+x ...


1

FileBot is a command-line tool that you can use in your shell scripts: http://www.filebot.net/cli.html


0

auto.sh has never run in a root context. prefs.sh did so up to Ubuntu 15.10 when it was sourced by /usr/sbin/guest-account, but the code has been refactored, and in 16.04 prefs.sh is sourced by /usr/share/lightdm/guest-session/setup.sh which is not run as root. Don't know if this change in behavior is intentional. If not, there may be a reason to propose a ...



Top 50 recent answers are included