Browsing articles tagged with "bash - 81/88 - Admins Goodies"
Aug 10, 2011
tom

Why does rc.local require absolute paths? How can I run a script at startup that doesn’t use them?

I have a script that runs at startup from rc.local in CentOS. This script contains a command to compile my erlang project using a third party build command called rebar. The rebar line fails to compile my project at startup, but if I then run it manually, the project compiles fine. I assume this is because the rebar command calls other commands without absolute paths. How can I run a command at startup, but in […]

Continue Reading »
Aug 10, 2011
tom

How do you run “source” when starting a shell?

In order to use rvm (https://rvm.beginrescueend.com/), I need to run source ~/.bash_profile each time when I start a new shell. How do I automatically do this when I start my computer, rather than having to type it each time? This is my .bash_profile: [[ -s "$HOME/.rvm/scripts/rvm" ]] && source “$HOME/.rvm/scripts/rvm” # Load RVM into a shell session *as a fu nction* [[ -s "$HOME/.rvm/scripts/rvm" ]] && . “$HOME/.rvm/scripts/rvm” # Load RVM function A few options […]

Continue Reading »
Aug 10, 2011
tom

Whhich is best way to do linux tasks via shell commands or via python scripts

I want to build the web interface for executing or doing linux tasks . Although there may be some existing tools but i have build a complete system on the top of that so i need to program that system myself. 1)Is Python/Django good for making that 2)E,g with basic commands like creating user / copying files , removing files. Is it better to use direct shell commands or python commands can be used for […]

Continue Reading »
Aug 10, 2011
tom

Permission Denied when using Sed

I am using Sed to find and replace a string in a file. This is the first time working with it so I maybe doing it wrong, I have a file thats owned by “root” called “test.properties” and I want to replace “world” with “cat”. So I run this command: sudo sed s/world/cat/ <test.properties >newtest.properties And it works great, but when I want to write to the SAME file like this: sudo sed s/world/cat/ <test.properties […]

Continue Reading »
Aug 10, 2011
tom

Python script take long time to backup folder

I copied this script from some book to make tar.bz2 of some folders for backup. #!/usr/bin/env python import tarfile, osdef make_tar(folder_to_backup, dest_folder, compression=’bz2′): if compression: dest_ext =’.’ + compression else: dest_ext = ” arcname = os.path.basename(folder_to_backup) dest_name = ‘%s.tar%s’ % (arcname, dest_ext) dest_path = os.path.join(dest_folder, dest_name) if compression: dest_cmp = ‘:’ + compression else: dest_cmp = ” out = tarfile.TarFile.open(dest_path, ‘w’ +dest_cmp) out.add(folder_to_backup, arcname) out.close() return dest_pathprint “Doing Python” make_tar(‘/home/bob/public_html’,’/home/bob/testbck’, compression=’bz2′) Now bash take 40 […]

Continue Reading »
Aug 10, 2011
tom

GNU screen clearing on vim,less,etc. exit

I’m very new to screen but have configured my ~/.screenrc file according to various recommendations I’ve found on the internet. I have one issue with it though which I’m sure could be resolved very easily; I think it’s a termcap setting..? After using less, vim, top, or other programs in standalone bash (on Mac OSX 10.6), upon exiting these programs, the terminal’s buffer will clear and the line above the current command line will be […]

Continue Reading »
Aug 10, 2011
tom

Sed in Bash Difficult pattern

I have a complicated string that I need to search for and replace I need to replace: common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar,/var/lib/tomcat6/common/classes,/var/lib/tomcat6/common/*.jar With #common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar,/var/lib/tomcat6/common/classes,/var/lib/tomcat6/common/*.jar common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar,/var/lib/tomcat6/common/classes,/var/lib/tomcat6/common/*.jar,${catalina.home}/lib/ext,${catalina.home}/lib/ext/*.jar I’m afraid that I can’t use python or any other scripting language (my bash script is currently 100+ lines) So far I have a test file that contains the string in question and I am trying to use this sed command: #!/bin/sh sed -i ‘s:common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar,/var/lib/tomcat6/common/classes,/var/lib/tomcat6/common/*.jar:#common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar,/var/lib/tomcat6/common/classes,/var/lib/tomcat6/common/*.jarncommon.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar,/var/lib/tomcat6/common/classes,/var/lib/tomcat6/common/*.jar,${catalina.home}/lib/ext,${catalina.home}/lib/ext/*.jar:’ workers.properties No errors are thrown, but nothing gets replaced […]

Continue Reading »
Aug 10, 2011
tom

How do I delete all empty directories

(on a Linux system) I have a large set of nested subdirectories on a filesystem. I would like to prune all directory paths that contain no files at all. In other words I would like to delete every directory where there are no files in that directory or in any subdirectory of that directory recursively. For all versions of find find -depth -type d -empty -exec rmdir {} ; If you have a newer version […]

Continue Reading »
Aug 10, 2011
tom

Bash script works from prompt but not from cron

When running a bash script from cron it fails with the following error /bin/sh: -c: line 0: unexpected EOF while looking for matching “’ /bin/sh: -c: line 1: syntax error: unexpected end of file The strange thing is it works perfectly when executed from the prompt Whole Script #!/bin/sh NOW=$(date +”%b-%d-%y”) bu_PATH=”/home/webserver/”curtime=$(date)echo “” echo “Starting backup: $curtime” echo “” echo “Moving to $bu_PATH” cd $bu_PATHBACKUP_FILE=”backup_$NOW.tgz”echo “” echo “The backup file will be called $BACKUP_FILE”RUN_BACKUP=”/usr/local/psa/bin/pleskbackup –server […]

Continue Reading »
Aug 10, 2011
tom

Preventing bash (and ksh) history alteration in Linux

From the looks of things, fixing ksh to make history alteration impossible is fairly easy. I’ve seen all the recommendations to make HIST* environment variables read-only, and the use of chattr to make the history file append-only (with chattr +a .sh_history). Bash, however, has two things which seem to make it impossible to prevent history alteration: the history command (with history -c and history -d) and the separation of the history file from the actual […]

Continue Reading »