Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › Share your Scripts
New Posts  All Forums:Forum Nav:

Share your Scripts - Page 3

post #21 of 302
Quote:
Originally Posted by Rookie1337 View Post

....
Unfortunately, I'm stumped as to why the following doesn't work. Sed complains about $ which makes me wonder...can it not handle variable substitution?
Code:
#!/bin/sh


realtime_on="realtime-scheduling = yes"
realtime_off="; realtime-scheduling = no"


sed /s/'$realtime_on'/'$realtime_off' daemon.conf 
....

You can, with something like so:
Code:
blah="test"
sblah="this is a test string"
echo $sblah | sed "s|$blah|cool|"

output: this is a cool string
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
post #22 of 302
I wrote this one to download the latest Nvidia driver.
Code:
#!/bin/bash

#
# Where do you keep your nVidia driver downloads? You MUST Edit this entry!!!
# Please Make Sure this name is correct - Do not include a "/" at the end...
#
nVidia_folder="/home/tom/Downloads"

# This is the base ulr for downloading the Linux Nvidia driver choose the one that best suites your location or add one of your own
# url=http://download.nvidia.com/XFree86/
url=ftp://download.nvidia.com/XFree86/
#url=http://us.download.nvidia.com/XFree86/


function download_driver {
    cd $nVidia_folder

    # Determine system architecture.
    # Only check for x86 or x86_64.  
    if [ -n "$( uname -m | grep -o 'x86_64' )" ];then
        architecture="Linux-x86_64"
    else
        architecture="Linux-x86"
    fi

    # This is the file that contains the version number of the latest Nvidia driver.
    # If it exists we are going to delete it so that we can download a fresh copy.
    if [ -f latest.txt ];
    then
    rm latest.txt
    fi
    wget $url/$architecture/latest.txt

    # String together the architecture, filename and url 
    driver=`awk '{if($NF ~ "NVIDIA-"+$architecture) {print $NF}}' latest.txt | sed -ne '1p'`
    drivername=$(basename "$driver")

    # Check if you have this version of the driver already, if not then download it.
    if [ -f $drivername ];
    then
    echo $driver exists3
    else

    # Download the driver
    wget $url/$architecture/$driver

    # Make it executable
    chmod +x ./$drivername
    fi
    return 0
}

download_driver
Core I7
(13 items)
 
  
CPUMotherboardGraphicsRAM
I7 920 rev. D0 @ 4.26Ghz EVGA X58 SLI EVGA GTX 285 OCZ XMP 3x2Gb (pc3 12800) 
Hard DriveOptical DriveOSMonitor
Western Digital Caviar Black 640Gb x 2 LG GH22LS30 openSuse 12.1 x64 HP F2105 
PowerCase
CORSAIR 850TX Cooler Master ATCS 840 
  hide details  
Reply
Core I7
(13 items)
 
  
CPUMotherboardGraphicsRAM
I7 920 rev. D0 @ 4.26Ghz EVGA X58 SLI EVGA GTX 285 OCZ XMP 3x2Gb (pc3 12800) 
Hard DriveOptical DriveOSMonitor
Western Digital Caviar Black 640Gb x 2 LG GH22LS30 openSuse 12.1 x64 HP F2105 
PowerCase
CORSAIR 850TX Cooler Master ATCS 840 
  hide details  
Reply
post #23 of 302
I've written an interesting script so I can sync my Eclipse workspaces between laptop and desktop.
Code:
#!/bin/bash

# This program syncs the eclipse workspace between the computers within my network

CreateEWORKSPACE="export EWORKSPACE=" # Create a Global Variable called EWORKSPACE
CreateDESTINATION="export DESTINATION=" # Create a Global Variable called DESTINATION
ENVIRONMENT=/etc/environment # Where the Global Variables will be written to.

# Below will execute if no argument is passed

[ $# -eq 0 ] && {

echo "Usage: lesync [ argument ]"
echo 
echo "arguments: "
echo "-u, --upload        upload to destination"
echo "-d, --download      download from destination"
echo "-nd                 use temporary destination"

exit 0;

}

# Checks to see if Global Variable EWORKSPACE exists, if not, you will be asked to define the directory of it.

if [ ! -n "$EWORKSPACE" ]; then
    echo "Eclipse Workspace directory is not defined"
    read -p "Define directory of your current Eclipse Workspace: " defineEWORKSPACE
    sudo echo "$CreateEWORKSPACE$defineEWORKSPACE" >> "$ENVIRONMENT"
fi

# Checks to see if Global Variable DESTINATION exists, if not, you will be asked to define the directory of it.

if [ ! -n "$DESTINATION" ]; then
    echo "destination not found.";
    read -p "Define directory of the destination: " defineDESTINATION
    sudo echo "$CreateDESTINATION$defineDESTINATION" >> "$ENVIRONMENT"
fi

# Makes a hidden folder for the workspaces to merge

if [ ! -d "$DESTINATION/.EWorkspace" ]; then
        cd $DESTINATION
        mkdir .EWorkspace
fi

# if option -u, --upload, or -U are used, it will upload data to the server

if [[ $1 == "-u" || $1 == "--upload" || $1 == "-U" ]]; then
    echo "Syncing..."

    cp -fR $EWORKSPACE/* $DESTINATION/.EWorkspace

    if [[ $? -eq 0 ]]; then
        echo "Successfully Synced."
    else
        echo "There was an error while syncing."
    fi
fi

# if option -d, --download, or -D are used, it will download data from the server

if [[ $1 == "-d" || $1 == "-D" || $1 == "--download" ]]; then
    echo "Downloading..."

    cp -fR $DESTINATION/.EWorkspace/* $EWORKSPACE

    if [[ $? -eq 0 ]]; then
        echo "Successfully downloaded."
    else
        echo "There was an error while downloading."
    fi
fi

# if option -nd, -Nd, -nD, or -ND are used, you can use a different server for the upload

if [[ $1 == "-nd" || $1 == "-Nd" || $1 == "-nD" || $1 == "-ND" ]]; then
    read -p "Define directory of temporary destination: " newDEST
    cd newDEST
    mkdir .Eworkspace
    cp -fR $EWORKSPACE/* $newDEST/.Eworkspace

    if [[ $? -eq 0 ]]; then
        echo "Successfully uploaded to $newDEST"
    else
        echo "There was an error while uploading to $newDEST"
    fi
fi

exit

Still rather new to bash scripting, and this is a crude script, but at least it works as I intended it to.
Already trying to figure out how to make it better, but it's a start at least.

please don't kill me redface.gif
lmao rig
(30 items)
 
lmao laptop
(20 items)
 
lmao server
(17 items)
 
CPUMotherboardGraphicsRAM
[AMD] Ryzen 5 1600X [Biostar] X370GT3 [Gigabyte] GTX 1080 windforce oc [G.Skill] Ripjaws V Series 16GB (2 x 8GB) DDR4 ... 
Hard DriveHard DriveHard DriveCooling
[Samsung] 960 evo m.2 250GB [Mushkin] eco2 512GB SSD [Mushkin] enhanced reactor 500GB SSD [Corsairl] h100i v2 
CoolingOSMonitorMonitor
[Noctua] nf-S12a pwm 120mm fan x 5 [M$] Winblows 10 pro fortified and telemetry free [AOC] i2367f 23" IPS [AOC] i2367f 23" IPS 
MonitorKeyboardPowerCase
[Dell] e2311h [Qisan] White Magicforce 68 w/ MX greens [Cougar] CMX 1000 [Fractal Design] Define C mini 
MouseMouse PadAudioAudio
[Logitech] g900 chaos spectrum [GGing] black extended mousepad [Onkyo] TX-SR313 receiver [KLH] Center and rear speakers 
AudioAudioAudioAudio
[Realistic] MC-1000 front speakers [Insignia] Rocketboost subwoofer Audio-Technica] QuietPoint ath-anc7b [Zalman] clip mic 
OtherOtherOtherOther
[Keycool] KC21 keypad w/ Gateron greens [Orico] USB 3.0 HDD dock bay [Orico] 7-port powered USB 3.0 Hub [Rosewill] 10-port powered USB 2.0 Hub 
OtherOther
[Belkin] 7-port powered USB 2.0 Hub [Phanteks] Cable extensions white 
CPUMotherboardGraphicsGraphics
[Intel] i7 6700HQ [Lenovo] ideapad y [Intel] HD 530 [AMD] Radeon R9 M375 4GB 
RAMRAMHard DriveHard Drive
[Samsung] 8GB DDR4 2133 [G.Skill] Ripjaws 8GB DDR4 2133 [Adata] Premier SP550 240GB SATA III M.2 SSD [Sandisk] X400 512GB SSD 
Optical DriveCoolingOSMonitor
[Asus] slim external DVD RW stock [M$] Winblows 10 fortified and telemetry free [Lenovo] 14" 1080p monitor 
KeyboardCaseMouseAudio
[Lenovo] integrated [Lenovo] y700 shell [Lenovo] touchpad integrated 
OtherOtherOtherOther
[Vortex] Poker II keyboard w/ MX Blacks [logitech] g303 daedalus apex mouse [WASD] v2 TKL w/ MX Clears (for work) [Dell] OEM optical mouse (for work) 
CPUMotherboardGraphicsRAM
[Intel] i7 2700k [Gigabyte] ga-z77-d3h [Intel] hd 3000 [G.Skill] Ares 16GB (4x4GB) DDR3 1600 
Hard DriveHard DriveHard DriveHard Drive
[Transcend] SSD320 128GB SSD (OS) [WD] Red 1TB [WD] Red 2TB [WD] Blue 1TB 
Hard DriveOptical DriveCoolingOS
[WD] Blue 2TB [Lite-on] dvd rw [Corsair] A70 Debian 9 Stretch x86_64 
PowerCaseOtherOther
[Antec] HCG 750w PSU [Antec] DF-35 [Biostar] USB 3.0 front bracket [kingwin] 3.5" hotswap bay (x2) 
Other
[Highpoint] Rocket 620 
  hide details  
Reply
lmao rig
(30 items)
 
lmao laptop
(20 items)
 
lmao server
(17 items)
 
CPUMotherboardGraphicsRAM
[AMD] Ryzen 5 1600X [Biostar] X370GT3 [Gigabyte] GTX 1080 windforce oc [G.Skill] Ripjaws V Series 16GB (2 x 8GB) DDR4 ... 
Hard DriveHard DriveHard DriveCooling
[Samsung] 960 evo m.2 250GB [Mushkin] eco2 512GB SSD [Mushkin] enhanced reactor 500GB SSD [Corsairl] h100i v2 
CoolingOSMonitorMonitor
[Noctua] nf-S12a pwm 120mm fan x 5 [M$] Winblows 10 pro fortified and telemetry free [AOC] i2367f 23" IPS [AOC] i2367f 23" IPS 
MonitorKeyboardPowerCase
[Dell] e2311h [Qisan] White Magicforce 68 w/ MX greens [Cougar] CMX 1000 [Fractal Design] Define C mini 
MouseMouse PadAudioAudio
[Logitech] g900 chaos spectrum [GGing] black extended mousepad [Onkyo] TX-SR313 receiver [KLH] Center and rear speakers 
AudioAudioAudioAudio
[Realistic] MC-1000 front speakers [Insignia] Rocketboost subwoofer Audio-Technica] QuietPoint ath-anc7b [Zalman] clip mic 
OtherOtherOtherOther
[Keycool] KC21 keypad w/ Gateron greens [Orico] USB 3.0 HDD dock bay [Orico] 7-port powered USB 3.0 Hub [Rosewill] 10-port powered USB 2.0 Hub 
OtherOther
[Belkin] 7-port powered USB 2.0 Hub [Phanteks] Cable extensions white 
CPUMotherboardGraphicsGraphics
[Intel] i7 6700HQ [Lenovo] ideapad y [Intel] HD 530 [AMD] Radeon R9 M375 4GB 
RAMRAMHard DriveHard Drive
[Samsung] 8GB DDR4 2133 [G.Skill] Ripjaws 8GB DDR4 2133 [Adata] Premier SP550 240GB SATA III M.2 SSD [Sandisk] X400 512GB SSD 
Optical DriveCoolingOSMonitor
[Asus] slim external DVD RW stock [M$] Winblows 10 fortified and telemetry free [Lenovo] 14" 1080p monitor 
KeyboardCaseMouseAudio
[Lenovo] integrated [Lenovo] y700 shell [Lenovo] touchpad integrated 
OtherOtherOtherOther
[Vortex] Poker II keyboard w/ MX Blacks [logitech] g303 daedalus apex mouse [WASD] v2 TKL w/ MX Clears (for work) [Dell] OEM optical mouse (for work) 
CPUMotherboardGraphicsRAM
[Intel] i7 2700k [Gigabyte] ga-z77-d3h [Intel] hd 3000 [G.Skill] Ares 16GB (4x4GB) DDR3 1600 
Hard DriveHard DriveHard DriveHard Drive
[Transcend] SSD320 128GB SSD (OS) [WD] Red 1TB [WD] Red 2TB [WD] Blue 1TB 
Hard DriveOptical DriveCoolingOS
[WD] Blue 2TB [Lite-on] dvd rw [Corsair] A70 Debian 9 Stretch x86_64 
PowerCaseOtherOther
[Antec] HCG 750w PSU [Antec] DF-35 [Biostar] USB 3.0 front bracket [kingwin] 3.5" hotswap bay (x2) 
Other
[Highpoint] Rocket 620 
  hide details  
Reply
post #24 of 302
Quote:
Originally Posted by Rookie1337 View Post

So I'm thinking about trying to make my pulseaudio guide into a script so that way it's easier for people to do (already had one person post that my guide wasn't easy to follow redface.gif). So with that in mind I thought I'd try to put the links enorbet2 gave me to practice and started trying to use sed. Unfortunately, I'm stumped as to why the following doesn't work. Sed complains about $ which makes me wonder...can it not handle variable substitution?
Code:
#!/bin/sh


realtime_on="realtime-scheduling = yes"
realtime_off="; realtime-scheduling = no"


sed /s/'$realtime_on'/'$realtime_off' daemon.conf 

That's just the basics I'm working on. Plan on hopefully getting something more (possibly a finished script if I get enough help) by Monday. So...what am I doing wrong here with sed? And yes, the file I'm testing is in the same directory; I'll deal with full path directions later.

I think you're looking for something a little like this
Code:
sed -i "s/$realtime_on/$realtime_off/g" daemon.conf

Remember ' are literal quotes, they won't bring in your variable because it thinks you want to actually look for $realtime_on, not "realtime-scheduling = yes".
post #25 of 302
Alright...now that I got the whole passing variables to sed thing fixed; how do I turn this mess into a functional script?
String of sed commands (Click to show)
Code:
#!/bin/sh


realtime_on="  realtime-scheduling = yes" #spacing has to match
realtime_off="; realtime-scheduling = no" #spacing has to match
realtime_priority_on="  realtime-priority = 40"
realtime_priority_off="; realtime-priority=9"
best_resampling="  resample-method = src-sinc-best-quality"
default_resampling="; resample-method = speex-float-10"
default_eq="; flat-volumes = yes"
best_eq="  flat-volumes = no"
default_rtlimit="; rlimit-rtprio = 9"
best_rtlimit="  rlimit-rtprio = 40"

#This section enables the changes you want from default
#sed -n "s/$realtime_on/$realtime_off/g" daemon.conf 
#sed -n "s/$realtime_priority_off/$realtime_priority_on/g" daemon.conf
#sed -n "s/$default_resampling/$best_resampling/g" daemon.conf
#sed -n "s/$default_eq/$best_eq/g" daemon.conf
#sed "s/$default_rtlimit/$best_rtlimit/g" daemon.conf

#This section returns everything to default
sed -n "s/$realtime_off/$realtime_on/g" daemon.conf 
sed -n "s/$realtime_priority_on/$realtime_priority_off/g" daemon.conf
sed -n "s/$best_resampling/$default_resampling/g" daemon.conf
sed -n "s/$best_eq/$default_eq/g" daemon.conf
sed "s/$best_rtlimit/$default_rtlimit/g" daemon.conf

In it's current form it just runs the last command and ignores the rest. I tried doing something with {}s but it didn't work either.

I thought I could just do something like:
Code:
sed -e { command1
command2}

@herkalurk@: what does the -i option do that I need? I'm confused...I thought it was for insertion not replacement.
     
CPUGraphicsRAMHard Drive
Intel Core m3-6Y30 Intel HD515 8GB 1866DDR3L Micron M600 MTFDDAV256MBF M.2, 256 GB 
CoolingOSOSMonitor
Fanless Win10 Home x64 Kubuntu 16.04 (requires Linux kernel 4.5/4.6) 13.3 inch 16:9, 1920x1080 pixel, AU Optronics A... 
CPUMotherboardGraphicsRAM
AthlonIIX4 640 3.62GHz (250x14.5) 2.5GHz NB Asus M4A785TD-M EVO MSI GTX275 (Stock 666) 8GBs of GSkill 1600 
RAMHard DriveHard DriveHard Drive
4GBs of Adata 1333 Kingston HyperX 3k 120GB WD Caviar Black 500GB Hitachi Deskstar 1TB 
Optical DriveCoolingOSOS
LG 8X BDR (WHL08S20) Cooler Master Hyper 212+ Kubuntu x64 Windows 7 x64 
OSMonitorPowerCase
Bodhi Linux x64 Acer G215H (1920x1080) Seasonic 520 HAF912 
CPUMotherboardGraphicsRAM
N450 1.8GHz AC and 1.66GHz batt ASUS proprietary for 1001P GMA3150 (can play bluray now!?) 1GB DDR2 
Hard DriveOptical DriveOSOS
160GB LGLHDLBDRE32X Bodhi Linux Fedora LXDE 
OSOSMonitorKeyboard
Kubuntu SLAX 1280x600 + Dell 15inch Excellent! 
PowerCase
6 cells=6-12hrs and a charger 1001P MU17 Black 
  hide details  
Reply
     
CPUGraphicsRAMHard Drive
Intel Core m3-6Y30 Intel HD515 8GB 1866DDR3L Micron M600 MTFDDAV256MBF M.2, 256 GB 
CoolingOSOSMonitor
Fanless Win10 Home x64 Kubuntu 16.04 (requires Linux kernel 4.5/4.6) 13.3 inch 16:9, 1920x1080 pixel, AU Optronics A... 
CPUMotherboardGraphicsRAM
AthlonIIX4 640 3.62GHz (250x14.5) 2.5GHz NB Asus M4A785TD-M EVO MSI GTX275 (Stock 666) 8GBs of GSkill 1600 
RAMHard DriveHard DriveHard Drive
4GBs of Adata 1333 Kingston HyperX 3k 120GB WD Caviar Black 500GB Hitachi Deskstar 1TB 
Optical DriveCoolingOSOS
LG 8X BDR (WHL08S20) Cooler Master Hyper 212+ Kubuntu x64 Windows 7 x64 
OSMonitorPowerCase
Bodhi Linux x64 Acer G215H (1920x1080) Seasonic 520 HAF912 
CPUMotherboardGraphicsRAM
N450 1.8GHz AC and 1.66GHz batt ASUS proprietary for 1001P GMA3150 (can play bluray now!?) 1GB DDR2 
Hard DriveOptical DriveOSOS
160GB LGLHDLBDRE32X Bodhi Linux Fedora LXDE 
OSOSMonitorKeyboard
Kubuntu SLAX 1280x600 + Dell 15inch Excellent! 
PowerCase
6 cells=6-12hrs and a charger 1001P MU17 Black 
  hide details  
Reply
post #26 of 302
Quote:
Originally Posted by CSCoder4ever View Post

I've written an interesting script so I can sync my Eclipse workspaces between laptop and desktop. Warning: Spoiler! (Click to show)
Code:
#!/bin/bash

# This program syncs the eclipse workspace between the computers within my network

CreateEWORKSPACE="export EWORKSPACE=" # Create a Global Variable called EWORKSPACE
CreateDESTINATION="export DESTINATION=" # Create a Global Variable called DESTINATION
ENVIRONMENT=/etc/environment # Where the Global Variables will be written to.

# Below will execute if no argument is passed

[ $# -eq 0 ] && {

echo "Usage: lesync [ argument ]"
echo 
echo "arguments: "
echo "-u, --upload        upload to destination"
echo "-d, --download      download from destination"
echo "-nd                 use temporary destination"

exit 0;

}

# Checks to see if Global Variable EWORKSPACE exists, if not, you will be asked to define the directory of it.

if [ ! -n "$EWORKSPACE" ]; then
    echo "Eclipse Workspace directory is not defined"
    read -p "Define directory of your current Eclipse Workspace: " defineEWORKSPACE
    sudo echo "$CreateEWORKSPACE$defineEWORKSPACE" >> "$ENVIRONMENT"
fi

# Checks to see if Global Variable DESTINATION exists, if not, you will be asked to define the directory of it.

if [ ! -n "$DESTINATION" ]; then
    echo "destination not found.";
    read -p "Define directory of the destination: " defineDESTINATION
    sudo echo "$CreateDESTINATION$defineDESTINATION" >> "$ENVIRONMENT"
fi

# Makes a hidden folder for the workspaces to merge

if [ ! -d "$DESTINATION/.EWorkspace" ]; then
        cd $DESTINATION
        mkdir .EWorkspace
fi

# if option -u, --upload, or -U are used, it will upload data to the server

if [[ $1 == "-u" || $1 == "--upload" || $1 == "-U" ]]; then
    echo "Syncing..."

    cp -fR $EWORKSPACE/* $DESTINATION/.EWorkspace

    if [[ $? -eq 0 ]]; then
        echo "Successfully Synced."
    else
        echo "There was an error while syncing."
    fi
fi

# if option -d, --download, or -D are used, it will download data from the server

if [[ $1 == "-d" || $1 == "-D" || $1 == "--download" ]]; then
    echo "Downloading..."

    cp -fR $DESTINATION/.EWorkspace/* $EWORKSPACE

    if [[ $? -eq 0 ]]; then
        echo "Successfully downloaded."
    else
        echo "There was an error while downloading."
    fi
fi

# if option -nd, -Nd, -nD, or -ND are used, you can use a different server for the upload

if [[ $1 == "-nd" || $1 == "-Nd" || $1 == "-nD" || $1 == "-ND" ]]; then
    read -p "Define directory of temporary destination: " newDEST
    cd newDEST
    mkdir .Eworkspace
    cp -fR $EWORKSPACE/* $newDEST/.Eworkspace

    if [[ $? -eq 0 ]]; then
        echo "Successfully uploaded to $newDEST"
    else
        echo "There was an error while uploading to $newDEST"
    fi
fi

exit
Still rather new to bash scripting, and this is a crude script, but at least it works as I intended it to.
Already trying to figure out how to make it better, but it's a start at least.

please don't kill me redface.gif

You really should be using git for this kind of thing. (Or any other kind of version control )
post #27 of 302
Quote:
Originally Posted by Plan9 View Post

Quote:
Originally Posted by CSCoder4ever View Post

I've written an interesting script so I can sync my Eclipse workspaces between laptop and desktop. Warning: Spoiler! (Click to show)
Code:
#!/bin/bash

# This program syncs the eclipse workspace between the computers within my network

CreateEWORKSPACE="export EWORKSPACE=" # Create a Global Variable called EWORKSPACE
CreateDESTINATION="export DESTINATION=" # Create a Global Variable called DESTINATION
ENVIRONMENT=/etc/environment # Where the Global Variables will be written to.

# Below will execute if no argument is passed

[ $# -eq 0 ] && {

echo "Usage: lesync [ argument ]"
echo 
echo "arguments: "
echo "-u, --upload        upload to destination"
echo "-d, --download      download from destination"
echo "-nd                 use temporary destination"

exit 0;

}

# Checks to see if Global Variable EWORKSPACE exists, if not, you will be asked to define the directory of it.

if [ ! -n "$EWORKSPACE" ]; then
    echo "Eclipse Workspace directory is not defined"
    read -p "Define directory of your current Eclipse Workspace: " defineEWORKSPACE
    sudo echo "$CreateEWORKSPACE$defineEWORKSPACE" >> "$ENVIRONMENT"
fi

# Checks to see if Global Variable DESTINATION exists, if not, you will be asked to define the directory of it.

if [ ! -n "$DESTINATION" ]; then
    echo "destination not found.";
    read -p "Define directory of the destination: " defineDESTINATION
    sudo echo "$CreateDESTINATION$defineDESTINATION" >> "$ENVIRONMENT"
fi

# Makes a hidden folder for the workspaces to merge

if [ ! -d "$DESTINATION/.EWorkspace" ]; then
        cd $DESTINATION
        mkdir .EWorkspace
fi

# if option -u, --upload, or -U are used, it will upload data to the server

if [[ $1 == "-u" || $1 == "--upload" || $1 == "-U" ]]; then
    echo "Syncing..."

    cp -fR $EWORKSPACE/* $DESTINATION/.EWorkspace

    if [[ $? -eq 0 ]]; then
        echo "Successfully Synced."
    else
        echo "There was an error while syncing."
    fi
fi

# if option -d, --download, or -D are used, it will download data from the server

if [[ $1 == "-d" || $1 == "-D" || $1 == "--download" ]]; then
    echo "Downloading..."

    cp -fR $DESTINATION/.EWorkspace/* $EWORKSPACE

    if [[ $? -eq 0 ]]; then
        echo "Successfully downloaded."
    else
        echo "There was an error while downloading."
    fi
fi

# if option -nd, -Nd, -nD, or -ND are used, you can use a different server for the upload

if [[ $1 == "-nd" || $1 == "-Nd" || $1 == "-nD" || $1 == "-ND" ]]; then
    read -p "Define directory of temporary destination: " newDEST
    cd newDEST
    mkdir .Eworkspace
    cp -fR $EWORKSPACE/* $newDEST/.Eworkspace

    if [[ $? -eq 0 ]]; then
        echo "Successfully uploaded to $newDEST"
    else
        echo "There was an error while uploading to $newDEST"
    fi
fi

exit
Still rather new to bash scripting, and this is a crude script, but at least it works as I intended it to.
Already trying to figure out how to make it better, but it's a start at least.

please don't kill me redface.gif

You really should be using git for this kind of thing. (Or any other kind of version control )

good point, doing a quick google search I could use git on my local network.
ah well, it was a good challenge anyways!
Edited by CSCoder4ever - 4/12/14 at 5:59am
lmao rig
(30 items)
 
lmao laptop
(20 items)
 
lmao server
(17 items)
 
CPUMotherboardGraphicsRAM
[AMD] Ryzen 5 1600X [Biostar] X370GT3 [Gigabyte] GTX 1080 windforce oc [G.Skill] Ripjaws V Series 16GB (2 x 8GB) DDR4 ... 
Hard DriveHard DriveHard DriveCooling
[Samsung] 960 evo m.2 250GB [Mushkin] eco2 512GB SSD [Mushkin] enhanced reactor 500GB SSD [Corsairl] h100i v2 
CoolingOSMonitorMonitor
[Noctua] nf-S12a pwm 120mm fan x 5 [M$] Winblows 10 pro fortified and telemetry free [AOC] i2367f 23" IPS [AOC] i2367f 23" IPS 
MonitorKeyboardPowerCase
[Dell] e2311h [Qisan] White Magicforce 68 w/ MX greens [Cougar] CMX 1000 [Fractal Design] Define C mini 
MouseMouse PadAudioAudio
[Logitech] g900 chaos spectrum [GGing] black extended mousepad [Onkyo] TX-SR313 receiver [KLH] Center and rear speakers 
AudioAudioAudioAudio
[Realistic] MC-1000 front speakers [Insignia] Rocketboost subwoofer Audio-Technica] QuietPoint ath-anc7b [Zalman] clip mic 
OtherOtherOtherOther
[Keycool] KC21 keypad w/ Gateron greens [Orico] USB 3.0 HDD dock bay [Orico] 7-port powered USB 3.0 Hub [Rosewill] 10-port powered USB 2.0 Hub 
OtherOther
[Belkin] 7-port powered USB 2.0 Hub [Phanteks] Cable extensions white 
CPUMotherboardGraphicsGraphics
[Intel] i7 6700HQ [Lenovo] ideapad y [Intel] HD 530 [AMD] Radeon R9 M375 4GB 
RAMRAMHard DriveHard Drive
[Samsung] 8GB DDR4 2133 [G.Skill] Ripjaws 8GB DDR4 2133 [Adata] Premier SP550 240GB SATA III M.2 SSD [Sandisk] X400 512GB SSD 
Optical DriveCoolingOSMonitor
[Asus] slim external DVD RW stock [M$] Winblows 10 fortified and telemetry free [Lenovo] 14" 1080p monitor 
KeyboardCaseMouseAudio
[Lenovo] integrated [Lenovo] y700 shell [Lenovo] touchpad integrated 
OtherOtherOtherOther
[Vortex] Poker II keyboard w/ MX Blacks [logitech] g303 daedalus apex mouse [WASD] v2 TKL w/ MX Clears (for work) [Dell] OEM optical mouse (for work) 
CPUMotherboardGraphicsRAM
[Intel] i7 2700k [Gigabyte] ga-z77-d3h [Intel] hd 3000 [G.Skill] Ares 16GB (4x4GB) DDR3 1600 
Hard DriveHard DriveHard DriveHard Drive
[Transcend] SSD320 128GB SSD (OS) [WD] Red 1TB [WD] Red 2TB [WD] Blue 1TB 
Hard DriveOptical DriveCoolingOS
[WD] Blue 2TB [Lite-on] dvd rw [Corsair] A70 Debian 9 Stretch x86_64 
PowerCaseOtherOther
[Antec] HCG 750w PSU [Antec] DF-35 [Biostar] USB 3.0 front bracket [kingwin] 3.5" hotswap bay (x2) 
Other
[Highpoint] Rocket 620 
  hide details  
Reply
lmao rig
(30 items)
 
lmao laptop
(20 items)
 
lmao server
(17 items)
 
CPUMotherboardGraphicsRAM
[AMD] Ryzen 5 1600X [Biostar] X370GT3 [Gigabyte] GTX 1080 windforce oc [G.Skill] Ripjaws V Series 16GB (2 x 8GB) DDR4 ... 
Hard DriveHard DriveHard DriveCooling
[Samsung] 960 evo m.2 250GB [Mushkin] eco2 512GB SSD [Mushkin] enhanced reactor 500GB SSD [Corsairl] h100i v2 
CoolingOSMonitorMonitor
[Noctua] nf-S12a pwm 120mm fan x 5 [M$] Winblows 10 pro fortified and telemetry free [AOC] i2367f 23" IPS [AOC] i2367f 23" IPS 
MonitorKeyboardPowerCase
[Dell] e2311h [Qisan] White Magicforce 68 w/ MX greens [Cougar] CMX 1000 [Fractal Design] Define C mini 
MouseMouse PadAudioAudio
[Logitech] g900 chaos spectrum [GGing] black extended mousepad [Onkyo] TX-SR313 receiver [KLH] Center and rear speakers 
AudioAudioAudioAudio
[Realistic] MC-1000 front speakers [Insignia] Rocketboost subwoofer Audio-Technica] QuietPoint ath-anc7b [Zalman] clip mic 
OtherOtherOtherOther
[Keycool] KC21 keypad w/ Gateron greens [Orico] USB 3.0 HDD dock bay [Orico] 7-port powered USB 3.0 Hub [Rosewill] 10-port powered USB 2.0 Hub 
OtherOther
[Belkin] 7-port powered USB 2.0 Hub [Phanteks] Cable extensions white 
CPUMotherboardGraphicsGraphics
[Intel] i7 6700HQ [Lenovo] ideapad y [Intel] HD 530 [AMD] Radeon R9 M375 4GB 
RAMRAMHard DriveHard Drive
[Samsung] 8GB DDR4 2133 [G.Skill] Ripjaws 8GB DDR4 2133 [Adata] Premier SP550 240GB SATA III M.2 SSD [Sandisk] X400 512GB SSD 
Optical DriveCoolingOSMonitor
[Asus] slim external DVD RW stock [M$] Winblows 10 fortified and telemetry free [Lenovo] 14" 1080p monitor 
KeyboardCaseMouseAudio
[Lenovo] integrated [Lenovo] y700 shell [Lenovo] touchpad integrated 
OtherOtherOtherOther
[Vortex] Poker II keyboard w/ MX Blacks [logitech] g303 daedalus apex mouse [WASD] v2 TKL w/ MX Clears (for work) [Dell] OEM optical mouse (for work) 
CPUMotherboardGraphicsRAM
[Intel] i7 2700k [Gigabyte] ga-z77-d3h [Intel] hd 3000 [G.Skill] Ares 16GB (4x4GB) DDR3 1600 
Hard DriveHard DriveHard DriveHard Drive
[Transcend] SSD320 128GB SSD (OS) [WD] Red 1TB [WD] Red 2TB [WD] Blue 1TB 
Hard DriveOptical DriveCoolingOS
[WD] Blue 2TB [Lite-on] dvd rw [Corsair] A70 Debian 9 Stretch x86_64 
PowerCaseOtherOther
[Antec] HCG 750w PSU [Antec] DF-35 [Biostar] USB 3.0 front bracket [kingwin] 3.5" hotswap bay (x2) 
Other
[Highpoint] Rocket 620 
  hide details  
Reply
post #28 of 302
Quote:
@herkalurk@: what does the -i option do that I need? I'm confused...I thought it was for insertion not replacement.

It means inline or inplace. You should really read man pages and search for your answer.

Simply it will change any occurence of string 1 to string 2, in whatever file is listed at the end of the command. I use it in a lot of scripts to setup systems for specific purposes, like change system parameters for oracle databases. I just had to write a script that is 2200 lines long. We are creating security hardended RHEL6 boxes for our VM template and the script to do all of the things the CIS guide has is giant. I have a 2ndary text file with all of the rules for auditd that the script has to insert.

Also based on what you have in your code, you are probably running all of those sed lines, but you placed all but the last in silent mode, so that's probably why you're not seeing any out put from them.
post #29 of 302
Thanks to the help of @herkalurk @enorbet2 and others I may have forgotten mention I've gotten past that block and now just need to add a few more variables and come up with a way to run or execute as sudo since IIRC you can't edit /etc/pulse/daemon.conf without it. Any ideas?

I also need to figure out how to make and then add users to an audio group such that they can have pulse run realtime privileged without having to resort to what I assume is a bad idea of setting rlimits for their specific user under /etc/security/limits.conf. I was thinking just add another section to do that later in the script and add it's variables at the beginning but I'm not sure.

Final question; if I wanted the script to tell people they need to restart the computer after it had finished making the changes would I just have it echo "Please restart the computer for changes to take effect"?

Also, if someone wants to improve or make a better version of the script they are more than welcome to help me. Thanks.

So progress as of right now:
Pulseaudio fixer script (Click to show)
Code:
#!/bin/sh
#Script made on April 12, 2014 by Rookie1337
#Goal is to make the "best" changes to pulseaudio

#This is the variable declaration section.
#Use a #before each set if you wish to disable a set.
#You need only change the numerical values of the priority;
#...and limits non-default settings to match your liking.

realtime_on="  realtime-scheduling = yes"
realtime_off="; realtime-scheduling = no"
realtime_priority_on="  realtime-priority = 40"
realtime_priority_off="; realtime-priority = 9"
best_resampling="  resample-method = src-sinc-best-quality"
default_resampling="; resample-method = speex-float-10"
default_eq="; flat-volumes = yes"
best_eq="  flat-volumes = no"
default_rtlimit="; rlimit-rtprio = 9"
best_rtlimit="  rlimit-rtprio = 40"

#This section enables the changes you want from default
sed "s/$realtime_off/$realtime_on/g ;
s/$realtime_priority_off/$realtime_priority_on/g ;
s/$default_resampling/$best_resampling/g ;
s/$default_eq/$best_eq/g ;
s/$default_rtlimit/$best_rtlimit/g" daemon.conf 


#This section returns everything to default
#Delete the # before each of the following lines;
#...and run the script again to undo all changes.
#sed "s/$realtime_on/$realtime_off/g ;
#s/$realtime_priority_on/$realtime_priority_off/g ;
#s/$best_resampling/$default_resampling/g ;
#s/$best_eq/$default_eq/g ;
#s/$best_rtlimit/$default_rtlimit/g" daemon.conf
     
CPUGraphicsRAMHard Drive
Intel Core m3-6Y30 Intel HD515 8GB 1866DDR3L Micron M600 MTFDDAV256MBF M.2, 256 GB 
CoolingOSOSMonitor
Fanless Win10 Home x64 Kubuntu 16.04 (requires Linux kernel 4.5/4.6) 13.3 inch 16:9, 1920x1080 pixel, AU Optronics A... 
CPUMotherboardGraphicsRAM
AthlonIIX4 640 3.62GHz (250x14.5) 2.5GHz NB Asus M4A785TD-M EVO MSI GTX275 (Stock 666) 8GBs of GSkill 1600 
RAMHard DriveHard DriveHard Drive
4GBs of Adata 1333 Kingston HyperX 3k 120GB WD Caviar Black 500GB Hitachi Deskstar 1TB 
Optical DriveCoolingOSOS
LG 8X BDR (WHL08S20) Cooler Master Hyper 212+ Kubuntu x64 Windows 7 x64 
OSMonitorPowerCase
Bodhi Linux x64 Acer G215H (1920x1080) Seasonic 520 HAF912 
CPUMotherboardGraphicsRAM
N450 1.8GHz AC and 1.66GHz batt ASUS proprietary for 1001P GMA3150 (can play bluray now!?) 1GB DDR2 
Hard DriveOptical DriveOSOS
160GB LGLHDLBDRE32X Bodhi Linux Fedora LXDE 
OSOSMonitorKeyboard
Kubuntu SLAX 1280x600 + Dell 15inch Excellent! 
PowerCase
6 cells=6-12hrs and a charger 1001P MU17 Black 
  hide details  
Reply
     
CPUGraphicsRAMHard Drive
Intel Core m3-6Y30 Intel HD515 8GB 1866DDR3L Micron M600 MTFDDAV256MBF M.2, 256 GB 
CoolingOSOSMonitor
Fanless Win10 Home x64 Kubuntu 16.04 (requires Linux kernel 4.5/4.6) 13.3 inch 16:9, 1920x1080 pixel, AU Optronics A... 
CPUMotherboardGraphicsRAM
AthlonIIX4 640 3.62GHz (250x14.5) 2.5GHz NB Asus M4A785TD-M EVO MSI GTX275 (Stock 666) 8GBs of GSkill 1600 
RAMHard DriveHard DriveHard Drive
4GBs of Adata 1333 Kingston HyperX 3k 120GB WD Caviar Black 500GB Hitachi Deskstar 1TB 
Optical DriveCoolingOSOS
LG 8X BDR (WHL08S20) Cooler Master Hyper 212+ Kubuntu x64 Windows 7 x64 
OSMonitorPowerCase
Bodhi Linux x64 Acer G215H (1920x1080) Seasonic 520 HAF912 
CPUMotherboardGraphicsRAM
N450 1.8GHz AC and 1.66GHz batt ASUS proprietary for 1001P GMA3150 (can play bluray now!?) 1GB DDR2 
Hard DriveOptical DriveOSOS
160GB LGLHDLBDRE32X Bodhi Linux Fedora LXDE 
OSOSMonitorKeyboard
Kubuntu SLAX 1280x600 + Dell 15inch Excellent! 
PowerCase
6 cells=6-12hrs and a charger 1001P MU17 Black 
  hide details  
Reply
post #30 of 302
Quote:
Originally Posted by Rookie1337 View Post

Thanks to the help of @herkalurk @enorbet2 and others I may have forgotten mention I've gotten past that block and now just need to add a few more variables and come up with a way to run or execute as sudo since IIRC you can't edit /etc/pulse/daemon.conf without it. Any ideas?
example prompt for sudo (Click to show)
Code:
#!/bin/bash

# check for root
# $UID 0 is root
if [ $UID != 0 ] ; then
  clear
  echo "This script requires root premissions to continue"
  read -p "(Y to continue anything else to exit)" y
  case $y in
      [Yy]* )
         # command to prompt for password
          sudo $0;
          Exit_Command=$?;;
      * )
          # exit script 
          Exit_Command=1
  esac
  exit $Exit_Command
fi

# script now has root privliges
echo "Root granted"
Quote:
Originally Posted by Rookie1337 View Post

Final question; if I wanted the script to tell people they need to restart the computer after it had finished making the changes would I just have it echo "Please restart the computer for changes to take effect"?

Yes, you could also ask them if they want to reboot now and do it for them, use the reboot or shutdown commands
Code:
shutdown -r now
or 
reboot
Core I7
(13 items)
 
  
CPUMotherboardGraphicsRAM
I7 920 rev. D0 @ 4.26Ghz EVGA X58 SLI EVGA GTX 285 OCZ XMP 3x2Gb (pc3 12800) 
Hard DriveOptical DriveOSMonitor
Western Digital Caviar Black 640Gb x 2 LG GH22LS30 openSuse 12.1 x64 HP F2105 
PowerCase
CORSAIR 850TX Cooler Master ATCS 840 
  hide details  
Reply
Core I7
(13 items)
 
  
CPUMotherboardGraphicsRAM
I7 920 rev. D0 @ 4.26Ghz EVGA X58 SLI EVGA GTX 285 OCZ XMP 3x2Gb (pc3 12800) 
Hard DriveOptical DriveOSMonitor
Western Digital Caviar Black 640Gb x 2 LG GH22LS30 openSuse 12.1 x64 HP F2105 
PowerCase
CORSAIR 850TX Cooler Master ATCS 840 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Linux, Unix
Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › Share your Scripts