New answers tagged

0

Try this one. The ln provides the test-and-set functionality. touch lock.$$.tmp if ln lock.$$.tmp lock.dat 2>/dev/null then echo "File is mine" else echo "Test and set failed" fi rm -f lock.$$.tmp


-1

Is it file or directory? If file, you can use simple command touch - if file exists, it just modify last access time. If file doesn't exists, is created.


2

Stealing an answer from various comments and links to [SO]. It seems there is a POSIX compliant method that doesn't involve mkdir as I mentioned in my original answer below set -o noclobber or set -C { > file ; } &> /dev/null This file and returns 0 or fails and returns non zero if file already exists. Original answer You'll have to use ...


0

With GNU bash 4: declare -i eighty_percent_ram_mb # set integer attribute while read -r a b c; do [[ $a =~ ^MemTotal: ]] && mem=$b; done < /proc/meminfo eighty_percent_ram_mb=$mem/100*80/1024


0

Someone just tweeted this to me! eighty_percent_ram_mb=$(free -m | awk 'NR==2{printf "%.0f\n", $2*0.8 }') I tried it and it worked.


2

eighty_percent_ram_mb=$(free -m | awk 'NR==2{printf "%d", $2*0.8 }') Should do the job :)


1

I would suggest executing the script from the sending side and using that to trigger the receive portion. There's no sense in starting a cron job on both ends... You can issue commands on your remote server from the local server using ssh.


0

kill -9 $(ps -eo comm,pid,etimes | awk '/^procname/ {if ($3 > 300) { print $2}}') where "procname" is a process name and 300 is running time threshold


0

If you didn't write the child scripts and have no control over there content, there may be no way to do what you want here. You get insight into the scripts you call directly by calling them with bash -x <scriptname> instead of relying on their executable bit. If you do have control of the content, consider using an environment variable to indicate ...


0

As simple as: #!/bin/bash echo ----Starting Backup---- echo Start Time: $(date +%m-%d-%Y) $(date +%H-%M) echo ------------------------ echo Deleting if older than 7 days echo ------------------------ find /var/application/application-data/exports/*.zip -mtime +7 -exec rm {} \; echo ------------------------ echo Sending to AppDataBkp echo ...


1

My help would be to use -delete instead of the exec rm ...


1

This is not related to Docker. You need to explicitly say passwd that you are going to provide password from stdin. echo 'newpassword' |passwd root --stdin


0

Instead of using commands, I would recommend you editing: /etc/sysconfig/network /etc/sysconfig/network-scripts/ifcg-[eth0,enp0s3] /etc/resolv.conf Make sure that ONBOOT="yes" on /etc/sysconfig/network-scripts/ifcg-[eth0,enp0s3] and you are good to go.


0

No, I don't think they are equivalent. The dot without following space replaces the path to your current directory, whereas a dot preceding a space makes commands of a script run in your current shell. There is a good explanation here : http://askubuntu.com/q/232932


0

In a lot of cases, depending on the software configure relies on having includes and headers opened from the current working directory. ansible does support a "chdir" argument. Maybe that is the solution that will work for you?


0

sed -n "s/^.*\(captureThis\).*$/\1/p" -n don't print lines s substitute ^.* matches anything before the captureThis \( \) capture everything between and assign it to \1 .*$ matches anything after the captureThis \1 replace everything with captureThis p print it


4

I may be wrong, but I believe that sudoers also restricts parameters that can be passed to a command/script, not just the command itself. If you try to run your .sh without the parameter it will likely work e.g. sudo /bin/bash /var/www/my_bash_script.sh So, to tell sudoers to allow that script to be run with any parameters (by apache), you would need ...


0

You can use the following settings Cmnd_Alias SVNUP = /root/webhooks/svn_update.sh apache ALL=(ALL) NOPASSWD: SVNUP Create simple test script # cat test.sh #!/bin/bash set -u echo "Param1: $1" Make simple tests $ id alex uid=506(alex) gid=506(alex) groups=506(alex) $ cat /root/webhooks/test.sh cat: /root/webhooks/test.sh: Permission denied $ sudo ...


1

Sudo has something called sudoreplay when enabled sessions is logged and can be replayed later, works similar as the script command that make a typescript of terminal session that later can be replayed with the scriptreplay command.


1

The results of pcs resource show ase157_res is op start timeout="20s" ? Since it takes 30 seconds to "/etc/init.d/that_script start", timeout= must be more than that.


3

Will Ansible prevent the execution of rm -rf / in a shell script? I did inspect the coreutils rm source, which has the following: if (x.recursive && preserve_root) { static struct dev_ino dev_ino_buf; x.root_dev_ino = get_root_dev_ino (&dev_ino_buf); if (x.root_dev_ino == NULL) error (EXIT_FAILURE, errno, ...


0

Have you tried simply adding an, exit 3, in the status function of the script to make it compliant? Something like this should work: # Check Sybase Adaptive Server and Backup Server status status() { dataserver=$(pidof dataserver) backupserver=$(pidof backupserver) if [ -n "$dataserver" ]; then echo "sybase Adaptive Server is running!" ...


-1

edit the file /etc/crontab and change the line MAILTO=root to MAILTO="" Source: http://michaelprogramming.blogspot.com/2014/01/disable-you-have-new-mail-in.html


0

In this case, you need only a substring match. a='foo "ok" bar'; [[ $a =~ ' "ok" ' ]] && echo found


3

Ok, it turns out I need [[:space:]] instead of [:space:]. No idea why, but the following works: if ! [[ $RESULT =~ [[:space:]"ok"[[:space:]] ]]; then


49

I have virtual machines, let's blow a bunch of them up! For science. [root@diaf ~]# ansible --version ansible 2.0.1.0 config file = /etc/ansible/ansible.cfg configured module search path = Default w/o overrides First attempt: [root@diaf ~]# cat killme.yml --- - hosts: localhost gather_facts: False tasks: - name: Die in a fire command: ...


4

Just add -r 0-1000 to your curl commandline, i.e.: STRING=$(curl -r 0-1000 -s http://localhost:8010/status?) Or generically you can use head -c 1000, i.e.: STRING=$(curl -s http://localhost:8010/status? | head -c 1000)


1

When doing redirect into the same file (>), shell may create/truncate the file before the cat command is invoked and the input is read (see: Why doesn't “sort file1 > file1” work?). If you want to filter the file, it's better to redirect the output into different file, or avoid redirection at all, for example: grep -v 'Apple' readme.log | tee readme.log ...


10

This happened because the first thing > does is to create the file it wants to write to - and if the file already exists, its contents will be deleted. (Also, there's no need at all to use cat in your statement since grep works on files, not just on STDIN.) The correct way to do this is to use a temporary file either to read from or to write to. So ...


0

Use lftp-4.7.1 and mirror --Move option. It will remove source files and empty folders. The option first appeared in lftp-4.7.0.


0

To allow lighttpd to execute files, enable the SELinux bool http_execmem. Then change the file type to allow lighttpd to be executed: chcon system_u:object_r:httpd_exec_t:s0 [file]. Keep that change persistent in the kernel by using semanage fcontext -a -t httpd_exec_t [file].


1

Summing up: Get url without (optional) suffix: url_without_suffix="${url%.*}" Get repository name: reponame="$(basename "${url_without_suffix}")" Get user (host) name afterwards: hostname="$(basename "${url_without_suffix%/${reponame}}")"


0

You can use Vim in Ex mode: ex -sc 'g/98\.76\.54\.32/d' -cx known_hosts g global search d delete x save and close


0

You can use tee as well, using uniq output as input: uniq .bash_history | tee .bash_history


3

Hmm. I think you can get around this with ansible's raw module. Remember that while rbash is a restricted shell, it's entirely possible to start an unrestricted subshell; it's meant more to prevent accidents than to provide security. So this is what I would do. I've tested this and confirmed it successfully changes a restricted shell. Note that it has to ...


0

You can use Vim in Ex mode: ex -sc '%!uniq' -cx .bash_history % select all lines ! run command x save and close


1

##Simulate an upgrade and grep for the firefox package ##Feel free to replace ' firefox' with something more specific RET=apt-get -s upgrade | grep firefox if [ $ret -eq 0 ] then echo "I don't have access to a debian box right now" fi From: http://unix.stackexchange.com/questions/19470/list-available-updates-but-do-not-install-them


-2

Try to use apticron apt-get install apticron After installation configure it here: /etc/apticron/apticron.conf It will give you a daily notification on mail if anything need to be updated.


0

You can check version of programs installed under apt with command: dpkg -l You can check a current package by referencing the Ubuntu Packages Search. Alternatively, for any package under apt (assuming that you have the updates repository enabled), you can use the apt-get command to update your package information and check for upgrades: apt-get update ...



Top 50 recent answers are included