...
  • Home
  • Shell
    • Emacs
    • Perl
    • screen
    • sed
  • Ubuntu
    • VNC
  • Web Development
    • Javascript
    • Joomla
    • MySQL
    • osTicket
  • Windows
    • Gimp
KEEP IN TOUCH

Most Popular

  • osTickets > Reports v4.2 (18056)
  • HTPC > Setup Windows 7 as a Media Center with XBMC (10962)
  • osTicket > View headers for original email message (4173)
  • WebDev > Allow PHP in Wordpress Widgets (3615)
  • Web Dev > Password protect webpage(s) with PHP & LDAP (2475)

Posts in category BASH

BASH > Recursively set file/directory permissions

Jan19
2012
1 Comment Written by Scott Rowley

Move to the directory you want to start chmodding files in and run the following:

Recursively set FILE permissions.

find . -type f -exec chmod 644 {} \;

Recursively set DIRECTORY permissions.

find . -type d -exec chmod 755 {} \;

*Note, obviously you can change the chmod number to whatever you want, 777, 600, etc.

ajax loader
Tagged chmod, chmodding, directory, file, files, find, permission, recursive, recursively, set, type
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

Recursively set group permissions to match owner permissions

Oct10
2011
Leave a Comment Written by Scott Rowley

I have had need of this multiple times in the past, just making a note of it here:

chmod -R g=u directory_name/
ajax loader
Tagged chmod, directory, group, owner, permissions, recursive
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

Linux > Aliases

Jun08
2011
1 Comment Written by Scott Rowley

Aliases can be a great way to more easily remember an oddball command or to shorten a long command. Aliases are stored in your .profile or within a include file referenced from .profile.

A couple of quick examples before showing how to set them up:
READ MORE »

ajax loader
Posted in Ubuntu - Tagged alias, basic, conditional, ggrep, grep, if, include, linux, profile, reload, solaris, ubuntu, unix, whois
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

Linux > Command line shortcuts

Jun06
2011
Leave a Comment Written by Scott Rowley

Another starter article to grow with my needs, we’ll start off with the shebang, or bang…or simply “!”. The first two commands I believe are the most useful and could be commonly used. Note that some of these can be a bit difficult to remember, we’ll also go over making aliases so we can use something a little easier to remember in a later article.
READ MORE »

ajax loader
Posted in Ubuntu - Tagged !, bang, command, date, exclamation, execute, home, last, previous, print, prior, shebang, shortcut, tilde
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

AWK > Useful examples

May26
2011
Leave a Comment Written by Scott Rowley

Just a starter page that will grow as I find useful awk commands to share.

Convert Linux .txt to Windows .txt
Replace the end of a line with a carriage. Useful for converting .txt files from Linux to Windows.

awk 'sub("$", "\r")' linuxfile.txt > windowsfile.txt

Convert Windows .txt to Linux .txt
And the reverse. Useful for converting .txt files from Windows to Linux.

awk '{ sub("\r$", ""); print }' windowsfile.txt > linuxfile.txt
ajax loader
Tagged awk, convert, example, linux, list, sub, txt, Windows
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

BASH > Colorize your ‘cat’ output

Apr07
2011
Leave a Comment Written by Scott Rowley

Ok, well thats a bit misleading. We won’t actually be using ‘cat’ but ‘pygmentize’ and its not perfect, but its better than 1 single color

This runs on Debian/Gentoo based Linux systems

apt-get update
apt-get install pygmentize

Once thats been installed what I did was to make an alias in my .profile

alias pcat='pygmentize'

Make sure to reload your .profile if you’ve added your alias

cd ~
. .profile

Example cat and pcat outputs:
Cat OutputPygmentize Output

ajax loader
Tagged alias, cat, pcat, pygmentize, ubuntu
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

BASH > Check for last day of the month

Apr01
2011
Leave a Comment Written by Scott Rowley

Script is meant to be used with other scripts in order to determine if it is the last day of the month. Useful for making sure a particular script runs at the end of the month. Just add a cron job that checks this every day at the time you would want your code run if it was indeed the last day of the month.

2 0 * * * /usr/bin/last-day-of-the-month.sh
#!/usr/bin/bash
# last-day-of-the-month.sh
# By: Scott Rowley
# http://www.sudobash.net/
#########################################

TODAY=`/usr/local/bin/date +%d`
TOMORROW=`/usr/local/bin/date +%d -d "1 day"`

# See if tomorrow's day is less than today's
if [ $TOMORROW -lt $TODAY ]
 then
  echo "Today is the last day of the month, running code..."
  /run/your/code
fi

exit 1
ajax loader
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

BASH > sudo bash

Mar31
2011
Leave a Comment Written by Scott Rowley

*Note – This is not an original sudobash.net article – credit goes completely to
http://www.gratisoft.us/sudo/man/1.8.0/sudo.man.html.  But I know people use search engines on ‘sudo bash’ and end up here so why not provide the answer as well? ;)

sudo, sudoedit – execute a command as another user

SYNOPSIS

sudo [-D level] -h | -K | -k | -V

sudo -v [-AknS] [-a auth_type] [-D level] [-g group name|#gid] [-p prompt] [-u user name|#uid]

sudo -l[l] [-AknS] [-a auth_type] [-D level] [-g group name|#gid] [-p prompt] [-U user name] [-u user name|#uid] [command]

sudo [-AbEHnPS] [-a auth_type] [-C fd] [-D level] [-c class|-] [-g group name|#gid] [-p prompt] [-r role] [-t type] [-u user name|#uid] [VAR=value] [-i | -s] [command]

sudoedit [-AnS] [-a auth_type] [-C fd] [-c class|-] [-D level] [-g group name|#gid] [-p prompt] [-u user name|#uid] file ...

DESCRIPTION
sudo allows a permitted user to execute a command as the superuser or another user, as specified by the security policy. The real and effective uid and gid are set to match those of the target user, as specified in the password database, and the group vector is initialized based on the group database (unless the -P option was specified).

sudo supports a plugin architecture for security policies and input/output logging. Third parties can develop and distribute their own policy and I/O logging modules to work seemlessly with the sudo front end. The default security policy is sudoers, which is configured via the file /etc/sudoers, or via LDAP. See the PLUGINS section for more information.

The security policy determines what privileges, if any, a user has to run sudo. The policy may require that users authenticate themselves with a password or another authentication mechanism. If authentication is required, sudo will exit if the user’s password is not entered within a configurable time limit. This limit is policy-specific; the default password prompt timeout for the sudoers security policy is 5 minutes.

Security policies may support credential caching to allow the user to run sudo again for a period of time without requiring authentication. The sudoers policy caches credentials for 5 minutes, unless overridden in sudoers(5). By running sudo with the -v option, a user can update the cached credentials without running a command.

When invoked as sudoedit, the -e option (described below), is implied.

Security policies may log successful and failed attempts to use sudo. If an I/O plugin is configured, the running command’s input and output may be logged as well.
READ MORE »

ajax loader
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

Web Dev > Report on server script status using popen

Mar24
2011
Leave a Comment Written by Scott Rowley

In your PHP page add something like the following:

$variable = popen("path/to/script.sh", 'r');
while (!feof($variable))  {
   echo fgets($variable);
   flush();
   ob_flush();
}
pclose($variable);

Then in your script you can echo the output like normal – though I recommend modifying it to spit out HTML like so:

while [ 1 ]
 do
   read CURRENT_ACCOUNT || break
   echo "Working with account  $CURRENT_ACCOUNT...<br />";
 done < list_of_accounts.txt

Then when you run the php page your webpage will be updated each time with the output of your script.sh until it is complete, then it will resume with the rest of your php code.

ajax loader
Posted in Web Development
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

BASH > ‘date’ command

Dec01
2010
Leave a Comment Written by Scott Rowley

Get a date in the past and change the output format:

date +'%Y-%m-%d' -d  "1 day ago"
2010-11-30
ajax loader
Tagged date, shell
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail
« Older Entries

Be Heard!

Authors needed! Feel like sharing your tech wisdom with the world? We are looking to expand our writer base and would love to hear from you. We need articles on any relevant technology/software/media/howto/etc (Well...lets at least hold to the legal stuff ;)

Just email scott (at) sudobash (dot) net

Corrections? Questions? Comments?

Find an error?
Everything work out great for you?
Have some feedback?
Like to see something added to the article?

PLEASE leave us a comment after the article and let us know how we are doing, or if something needs corrected, improved or clarified.

Thank you!
- The Management

Sudo Bash Member sites

Des Moines, Iowa Karate Classes
Iowa MMA Tournaments
Iowa SAR
Ooo-er
5point Studios Tattoo & Piercing

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

RSS HowToGeek

  • Week in Geek: Aero Glass Feature will be Removed from Windows 8
  • How to Speed Up Web Browsing with Search & Bookmark Keywords
  • Geek Trivia: Pagers Were First Developed To Assist Which Professionals?
  • The Best Tips and Tricks for Using Email Efficiently
  • Desktop Fun: Starry Skies Wallpaper Collection Series 2

RSS TheGeekStuff

  • UNIX / Linux Processes: C fork() Function
  • How to Calculate IP Header Checksum (With an Example)
  • How to Encrypt Your Bash Shell Script on Linux Using SHC
  • Intro to DOCSIS Architecture, CM CMTS Protocol for Cable Modems
  • Ettercap Tutorial: DNS Spoofing & ARP Poisoning Examples

RSS LifeHacker

  • DIY Maple-Flavored Pancake Syrup [Breakfast]
  • This Week's Top Downloads [Download Roundup]
  • Make Mini Dutch Baby Pancakes in a Muffin Tin [Breakfast]
  • Pour Vinegar Down Your Drain Every Three Months to Keep Clogs Away [Video]
  • Use the Jelly Pocket Method for a Better Drip-Free PB&J [Food Hacks]

EvoLve theme by Blogatize  •  Powered by WordPress Sudo Bash
By Geeks - For Geeks

Back to Top