|
Programming C, bash, Python, Perl, PHP, Java, you name it. |
|
Thread Tools | Display Modes |
|
|||
Any interesting snippets?
Do any of you have any snippets or scripts you're working on?
Here's some quickies... fav is the last one, acts as a toggle - launches xorg if not currently running, else exits an xterm. Code:
alias ~ 'cd ~' alias - 'cd -' alias .. 'cd ..' alias x '[ $?DISPLAY -eq 0 ] && xinit || exit'
__________________
www.tacoshack.xyz |
|
|||
lol, IdOp's typo reminder alias.
Ahh - spelling & grammar. Me? My work is always error three... EDIT: Make that 'error free' =)
__________________
www.tacoshack.xyz |
|
|||
Here's two ~/.tcshrc keybindings for commandline volume control...
Code:
bindkey -c '^[OP' 'mixer vol +10' # key F1 increase volume 10% bindkey -c '^[OQ' 'mixer vol -10' # key F2 decrease volume 10% These are embedded key sequences which would necessarily require an editor capable of inserting such (I used plain old vi). For instance, to insert the raw keycode for F1, you would type the escape sequence CTRL+V (that's two key strokes - the control key followed by the v key) then press the F1 key. To create a list of raw keycodes... . invoke: cat <<end > raw-keys.txt . type CTRL+V then press a key . repeat 2nd step to populate your list . type 'end' to exit & save work to file Note: The above works great from the physical console, but less so in some terminal emulators.
__________________
www.tacoshack.xyz |
|
|||
For quite awhile now I've wanted to backup files on my server -from my local Windows box-
Of course that requires logging into my BSD server, running a backup script, & then logging out. Here, that chore takes about 15mins. during which I'd typically read some news, or maybe play a hand of Golf solitaire. Not unpleasant, but it kept me glued to that spot for the duration... What I needed was a way to automate the process. Make the task totally 'hands-off', 'cuz hey - thats what computers are for no? To do this I'd need to first run the remote backup script, & then (just to be safe), copy the remote backup to my Win box. Here then is my strategy...
Putty (a freeware suite of Windows tools including secure shell client, secure copy, secure ftp) is just the ticket. plink allows you to run a remote command from your localhost, while pscp allows you to copy files to/from a remote host. With these tools ready, I only needed to copy the backup script to the server (first script), & then launch it from the Windows side (2nd script, 'remote-backup.cmd'). At anyrate, comments are always welcome =) Save this snippet server-side... Code:
#!/bin/sh <<DOC this script creates a dated tar/gzip archive of all directories/files in your home directory in the form of 'user-date.tgz' while leaving older backup archives intact to use... - save script to your home directory as 'backup.sh' - flip on script's exec bit 'chmod +x ~/backup.sh' - run the script '~/backup.sh' DOC TGZ=$1 OLD=$USER-[0-9]*.tgz [ -z $TGZ ] && { echo backup file not specified... exit 1 } cd $HOME tar cvzf $TGZ --exclude=$OLD ./ || { echo backup error exit 1 } cd - # eof Code:
@echo off :: save script on windows as remote-backup.cmd :: :: requires plink & pscp, available in the putty package at: :: http://www.chiark.greenend.org.uk/~sgtatham/putty/ :: :: :: you'll need to change these 3 items... :: :: - remote host address :: - remote host login name :: - remote host password set HST=192.168.0.8 set USR=warby-parker set PSW=chesseburger :: note: date formats vary between locales... :: this script uses the format: year, month, day :: to determine your local date format invoke: :: :: echo %date% :: :: to parse the date follow this example... :: :: set var=%date:~2,4% :: echo %var% :: :: where 'var' is a substring starting from the 2nd :: character of the main-string, 4 characters wide :: windows us-english date format *but double check* set Y=%date:~10,4% set M=%date:~4,2% set D=%date:~7,2% set TGZ=%USR%-%Y%%M%%D%.tgz :: dont change anything below... cls echo REMOTE BACKUP INITIATED... plink -pw %PSW% %USR%@%HST% backup.sh %TGZ% if not errorlevel 0 ( echo ERROR CREATING REMOTE BACKUP... exit /b 1 ) echo TRANSFERRING BACKUP TO LOCALHOST... pscp -pw %PSW% %USR%@%HST%:%TGZ% c:/%TGZ% if not errorlevel 0 ( echo ERROR TRANSFERRING BACKUP TO LOCALHOST... exit /b 1 ) echo REMOTE BACKUP COMPLETE... :: eof
__________________
www.tacoshack.xyz Last edited by Mike-Sanders; 1st March 2015 at 03:44 PM. |
|
||||
I don't like display managers so instead of xdm(1) I use this line in ~/.profile:
Code:
[[ -z $DISPLAY && $(tty) = /dev/ttyC0 ]] && exec startx |
Tags |
alias, csh, script, shell, tcsh |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
NixOS - an interesting Linux distro. | TerryP | Off-Topic | 2 | 21st February 2011 07:44 PM |
Interesting disscussion on: Solaris vs HP-UX vs AIX | vermaden | Other BSD and UNIX/UNIX-like | 2 | 19th May 2010 09:33 AM |
Other Interesting "Security" Issue on GRUB 2 | vermaden | News | 2 | 10th November 2009 01:19 PM |
An interesting benchmark (kqueue vs. epoll) | mdh | Programming | 0 | 9th October 2008 09:49 PM |