Unix@nashikouen

teh place for hakin and computers. also site discussion.
[Return] [bottom] [Catalog]
Posting mode: Reply
submition rules
  • Allowed file types are: .jpg, .png, .gif, .webp, .mp4, .mov, .webm, .mp3, .wav, .ogg, .flac, .swf, .swf
  • maximum files: 3
  • maximum upload size: 40.00 MB
  • duplicate files are not allowed
  • posts will be displayed in UTC time
  • max comment size is 8048 characters
  • tripcodes are enabled
  • BBCode is enabled

  • What are some short scripts you use on your systems that might be useful for others?
    Here's a couple on mine (edited for brevity):

    [code]
    #!/bin/sh
    #get-ip.sh
    #get this machine's local LAN address
    #use "inet6.*wlan0" if you want the IPv6 address
    ip address | grep "inet.*wlan0"
    [/code]
    ex: get-ip.sh

    [code]
    #!/bin/sh
    #rand-vid.sh, needs mpv, I generally call this from the GUI
    #play random videos from my videos folder
    vidfolder="$HOME/Videos/" #change this to your videos folder
    mpv --geometry=320x240 --shuffle --no-loop-file --loop-playlist --mute "$vidfolder"
    [/code]
    ex: rand-vid.sh

    there are a few more useful ones I have, but they're really long now after bolting on a bunch of stuff
    this one is super simplified from what's on disk, for example, there's proper argument handling there:

    [code]
    #!/bin/bash
    #image-with-sound.sh image-file audio-file [framerate, default 10], needs ffmpeg
    #combine an audio track with a still image
    ffmpeg -r "${3:-10}" -loop 1 -i "$1" -i "$2" -acodec copy -vf scale=trunc"(in_w/2)*2:trunc(in_h/2)*2" -shortest "$1"-combined.mkv
    [/code]
    ex: image-with-sound.sh miku.png world-is-mine.mp3 5

    I have a script that stacks images (useful for show screenshots) and it's hilariously long because of argument handling but the core is
    [code]convert "$@" -gravity center "$stackmode" "$outputfile"[/code]
    but it's like 70 lines above that lol
    $stackmode can be either +append for horizontal layout or -append for vertical
    $outputfile is just the target
    mostly end up using vertical, so a ready-to use version is:

    [code]
    #!/bin/bash
    #stack-imgs.sh files-to-stack ..., needs imagemagick
    convert "$@" -gravity center -append "stacked-output.png"
    [/code]
    ex: stack-images.sh 1.png 2.png 3.png

    (also remember nashi, don't just blindly copy scripts if you don't understand them)

    >(also remember nashi, don't just blindly copy scripts if you don't understand them)

    good advice, becoz there's sneaky ways to get ppl to run things that (try to) b0rk their system.

    https://github.com/keroserene/rickrollrc
    this is one of my fav. each time i convert a person over to a UNIX system, i always hit them with this.

    >(also remember nashi, don't just blindly copy scripts if you don't understand them)

    there is quite a bit of people i know who are new to unix and use nashi!

    usually signs that show it is bad code is
    rm / *
    find -exc "dadcf78b929b78ac2dfa9b7" | /dev/null
    culr example.com/file.sh | bash

    noticed several scripts I use have a fancy countdown that is basically like
    echo "5..."; sleep 1; echo "4..."; sleep 1; echo "3..."; sleep 1; echo "2..."; sleep 1; echo "1..."; sleep 1;

    you'd ^C whatever was going to happen before the countdown finished, it'd usually be for letting the user know that they'd already downloaded/processed a file but not just sit there doing nothing waiting for a yes answer if they walked away

    so I made a generic version
    there are certainly easier ways to do a countdown ("read -t 5" comes to mind) but it's not fancy ( ̄︶ ̄)↗

    exercise for the reader: use something involving "read -t 1" in the loop in place of "sleep 1" to end the countdown early by pressing enter as if you waited the full period
    too lazy to add it myself this second


    #!/bin/bash
    #countdown.sh [countdown-time]
    #fancy countdown that returns an error code if it's interrupted
    #use like
    # if ! countdown.sh 10; then exit 1; fi
    #or something in your scripts

    early_exit() {
    echo
    echo "Canceled."
    exit 1
    }
    trap 'early_exit' SIGINT

    count_in="${1:-5}"
    count_max=$(("$count_in"))

    echo "Press Ctrl+c to cancel."
    for (( c=$count_max; c>0; c-- ))
    do
    if (( $c == $count_max ))
    then
    echo -n "Continuing in $c seconds... "
    else
    echo -n "$c... "
    fi
    sleep 1
    done

    echo "Ok."
    exit 0

    now that bbcode works, I should re-post all the scripts in the OP so you can actually make them out

    so here:


    #!/bin/sh
    #get-ip.sh
    #get this machine's local LAN address
    #use "inet6.*wlan0" if you want the IPv6 address
    ip address | grep "inet.*wlan0"

    ex: get-ip.sh


    #!/bin/sh
    #rand-vid.sh, needs mpv, I generally call this from the GUI
    #play random videos from my videos folder
    vidfolder="$HOME/Videos/" #change this to your videos folder
    mpv --geometry=320x240 --shuffle --no-loop-file --loop-playlist --mute "$vidfolder"

    ex: rand-vid.sh

    there are a few more useful ones I have, but they're really long now after bolting on a bunch of stuff
    this one is super simplified from what's on disk, for example, there's proper argument handling there:


    #!/bin/bash
    #image-with-sound.sh image-file audio-file [framerate, default 10], needs ffmpeg
    #combine an audio track with a still image
    ffmpeg -r "${3:-10}" -loop 1 -i "$1" -i "$2" -acodec copy -vf scale=trunc"(in_w/2)*2:trunc(in_h/2)*2" -shortest "$1"-combined.mkv

    ex: image-with-sound.sh miku.png world-is-mine.mp3 5

    I have a script that stacks images (useful for show screenshots) and it's hilariously long because of argument handling but the core is
    convert "$@" -gravity center "$stackmode" "$outputfile"

    but it's like 70 lines above that lol
    $stackmode can be either +append for horizontal layout or -append for vertical
    $outputfile is just the target
    mostly end up using vertical, so a ready-to use version is:


    #!/bin/bash
    #stack-imgs.sh files-to-stack ..., needs imagemagick
    convert "$@" -gravity center -append "stacked-output.png"

    ex: stack-images.sh 1.png 2.png 3.png

    >>42
    >ip address | grep "inet.*wlan0"

    ip: Command not found.
    i use "ifconfig wlan0" and ive never heard of "ip"
    sadly i cannot contribute to this thread because i checked all my scripts and all of them are specialized and useless to other people! but i will leave a suggestion to write scripts for all your common rsync tasks if you use it often as i do.
    >>64
    whats the code tag? im new from heyuri

    oh its the same code tag as heyuri,
    [c0de] [/c0de] but replace the zeros with "o"s

    i dont kniw where you get ip command from but i usaly used it to get my ip all the time with
    ip a

    >>65
    ip (and a few other commands I can't remember) replaced ifconfig in recent Linux distros
    don't know why, but it's been like that for a while now
    I think you can still install ifconfig, it simply isn't default anymore.

    >>68
    interesting
    im on freebsd right now but ive always used ifconfig on linux
    >>66
    thanks

    somewhat related to this topic
    what do you think of linux distros replacing bash with alternative shells? i heard ubuntu replaced bash with dash? i know freeBSD systems default to (t)csh. is bash too slow/bloated?

    >>69
    i don't really know the difference between unix shells.
    OpenBSD uses ksh. I just use redirecting IO and pipes. any other features i don't really care about

    >>69
    bash is a bit bloated but I constantly use bashisms and install on any systems I use that don't have it
    but it is a huge attack surface because it does so much

    >>70
    >i don't really know the difference between unix shells.

    A lot of them are compatible with sh (the Bourne shell), but add features..
    bash is the "Bourne Again SHell" (note the caps), which bolts on tons and tons of features.
    In general, they're basically different scripting languages with their own featuresets, but work around the basic shell concepts of running commands and piping data around.

    There are shells that aren't sh compatible, like fish (which I've been meaning to give a chance since it's supposed to be very easy and clean, I just am stuck forever in bash land since it's very widely available, very featureful, and for years had a pretty good chance of being the default).

    I specialize in one liners so I will post some of those:

    Find all video files recursively in a directory

    find . -type f -exec bash -c '[[ "$( file -bi "$1" )" == video/* ]]' bash {} \; -print

    (run it inside your eroge directory for hours of fun!)

    Play all flash files in a directory in a random order, with 'q' to quit and any key to play the next one

    while read flash; do flashplayer "$flash"; read -n 1 < /dev/tty; [ "$REPLY" == "q" ] && break; done < <(ls -- *.swf | shuf)

    (can be adapted to any kind of file!)

    Those were the ones I could find from scrolling through my bash history for a few mins.

    [top]
    Delete Post: []
    Password:



    - you are running KotatsuBBS. a clear and easy to read image board software -