Ubuntu Scripts

I should have flashable Ubuntu USB image soon with all of these Ubuntu scripts in it but in the meanwhile (since I am so busy), you can use these commands to add start-up scripts and auto restart scripts to your Ubuntu system.

This guide is made for those of you who followed my other Ubuntu installation guide but if you know a bit about Ubuntu, you can tweak it to any Ubuntu installation.

How to Make Auto-Start Script for CGMiner!

Step 1. First, open a text editor then create a new file called cgminer.conf under the cgminer-3.7.2-x86_64-built directory.

Then put all of your configuration values here:


"pools" : [
"url" : "stratum+tcp://mint.hashstrike.com:3336",
"user" : "zedomax.152",
"pass" : "xxx"
"url" : "stratum+tcp://PutYourPoolInfoHere.com:3336",
"user" : "zedomax.152",
"pass" : "xxx"

"intensity" : "13",
"vectors" : "1",
"worksize" : "256",
"kernel" : "scrypt",
"thread-concurrency" : "8192",
"lookup-gap" : "2",
"gpu-engine" : "1020",
"gpu-fan" : "40-100",
"gpu-memclock" : "1475",
"gpu-powertune" : "20",
"shaders" : "2048",
"gpu-vddc" : "1.087",
"temp-cutoff" : "99",
"temp-overheat" : "95",
"temp-target" : "67",
"gpu-threads" : "2",
"no-pool-disable" : true,
"no-submit-stale" : true,
"queue" : "0",
"scan-time" : "1",
"expiry" : "1",
"auto-fan" : true,
"scrypt" : true,
"kernel-path" : "/usr/local/bin"

Then save. The above config is for R9 280X graphic cards. You will need to tweak if for other graphic cards as needed. (I will have some sample posting of that also soon for all the graphic cards I’ve tried.)

You can also set individual settings by doing something like:

"gpu-engine" : "1020,1020,1020,900,1000,1000",

if you have multiple graphic cards.

Having a config file is much easier so you can edit it easily later down the road and tweak your settings.

Step 2. Next create a file called “mine.sh” in your CGMiner directory and put the following:

export DISPLAY=:0
cd /home/litecoin/cgminer-3.7.2-x86_64-built
./cgminer -c cgminer.conf 

Change “/home/litecoin/cgminer-3.7.2-x86_64-built” to your user directory then Save.

Then open up a terminal and type:

chmod 755 mine.sh

That will change the permissions to run the script.

And you can test the script out by typing:

sh mine.sh

If Cgminer works fine, you are ready to go to next step, otherwise, you may need to edit the cgminer.conf file.

Step 3. Next, install screen by typing:

sudo apt-get install screen

Step 4. Next, use text editor and make a new file called “test.sh” in your user directory and put this:

temp=$(ps aux | grep cgminer | grep -v grep)
echo $temp

#if [[ "$temp" == *cgminer* ]]
if echo "$temp" | grep -q "cgminer"; then
        echo "CGMINER EXISTS!"
        su litecoin -c "screen -dmS cgm /home/litecoin/mine.sh"
        echo "WORKED!"

This script basically tests if cgminer is running and if it’s not running, it will start up the script located in /home/litecoin/mine.sh. You will need to change “/home/litecoin” to your user directory.

Next type:
sudo vi .bashrc

Then scroll all the way down to “# enable programmable completion features” and add this before that line by pressing “i” and pasting this:
alias cgm='screen -x cgm'

This will allow you to launch screen command easily by typing “cgm”. (Credits for this code to Cryptobadger.)

Then type:

chmod 755 test.sh

That will change the permissions to run the script.

And you can test the script out by typing:

sh test.sh

You should get “WORKED”. Then you can type “cgm” in terminal and you should be able to see CGMiner running. Anytime you want to see this, simply type “cgm”. To get out of the screen without interfering with CGMiner, simply press Ctrl+a+d on your keyboard.

This script will basically check if CGMiner is running and if it’s not running, it will launch it in the background using the screen command.

Step 5. Now, how do we get this script so it will make CGMiner to start at every reboot? We will use the Ubuntu Cron job function, and simply add couple lines.

Go to terminal and type:

sudo vi /etc/cron.d/saupdate

Then hit the “i” button and paste the following line:
*/4 * * * * root sh /home/litecoin/test.sh

Make sure you change “/home/litecoin” to your user directory!!!

Then hit Esc key and hit “:wq” and that will save the new cron job to start every 4 minutes so your machine will automatically start CGMiner whenever it reboots.

That’s it!

How to Make Your Ubuntu Rig Auto Re-Start!

If you want to make your Ubuntu rig auto re-start at certain times of the day, like every 3 hours (because I find that on some rigs, this is helpful to reset sick graphic cards and having your rig reset couple times a day may be more profitable than having few of your graphic cards sick all day long.), you can add this line to the cron job.

Step 1. Go to terminal and type:

sudo vi /etc/cron.d/saupdate

Then hit the “i” button and paste the following line after the first line:
0 */3 * * * root /sbin/shutdown -r now

Then hit Esc key and hit “:wq” and that will save the file.

This will reboot your machine every 3 hours. You can also change the value to your liking such as 6 hours, 12 hours, etc…etc..

I hope these scripts help you auto-start and also auto-restart your rigs. I know there’s a lot of code but you may learn a few things while typing out the code yourself.

I am currently in the process of building a Ubuntu USB Image so you can have all of the scripts, AMD drivers, and everything on this site without doing it yourself so when that’s available (soon), you will be able to simply flash it to your USB flash drive and get all of these things. But mind you, it may be a good thing to understand how the code works, then you can tweak it later to your liking. Enjoy!

Like my stuff? You can send me coins!
BTC: 15ZgN5mFaK2cK2wbR6yAm2CvdWZu3xmXmU

Want to Contact Me? I am on Twitter 24/7!
First time to digital currency?
Please see What is a Litecoin? FIRST!!!

25 thoughts on “Ubuntu Scripts

  1. zsar

    Well done sir! I will test those scripts tonight!
    Also, you should add a “donate” address (BTC, LTC, DOGE, etc), I’m pretty sure that a lot of people found your guides very helpful 🙂

    Stay HIGH on coins!



  2. Per Marius

    “sh mine.sh”
    No known USB devices?

    can not start cgminer with ” cgminer.conf ” and ” sh mine.sh file

    ” cgminer.conf ” :

    ” pools “: [
    ” url “: ” stratum + tcp :/ / ue2.multipool.us : 7777 ”
    “user “: ” 132132 ” ,
    “pass “: ” 132132 ”
    ” url “: ” stratum + tcp :/ / eu.multipool.us : 7777 ”
    “user “: ” 123132t ”
    “pass “: ” 132132 ”
    ” url “: ” stratum + tcp :/ / mining.usa.hypernova.pw : 3333 ”
    “user “: ” 132132 ” ,
    “pass “: ” 13213 ”

    ” intensity “: ” 13″ ,
    ” vectors “: ” 1″ ,
    “work size” : ” 256 ” ,
    ” kernel “: ” Scrypt ”
    ” thread- concurrency “: ” 8192 ” ,
    ” lookup- gap” , ” 2″ ,
    ” GPU engine” , ” 1075 ” ,
    ” GPU fan” , ” 40-100 ” ,
    ” GPU memclock “: ” 1500″ ,
    ” GPU power tune” : “20” ,
    ” shaders “: ” 2048 ” ,
    ” temp cutoff “: ” 99″ ,
    ” temp over heat “: ” 95″ ,
    ” temp -target “: ” 70″ ,
    ” GPU threads ” , ” 2″ ,
    “no- pool -disable ” : true ,
    “no- submit- stale” : true ,
    ” queue “: ” 0″ ,
    “scan -time “: ” 1″ ,
    ” expiry “: ” 1″ ,
    ” auto fan” : true ,
    ” Scrypt ” : true ,
    ” kernel- path” : “/ usr / local / bin”

    ” mine.sh ” :
    export DISPLAY = : 0
    export GPU_MAX_ALLOC_PERCENT = 100
    export GPU_USE_SYNC_OBJECTS = 1
    cd / Hjem/Nedlastinger/cgminer-3.7.2-x86_64-built
    . / cgminer -n cgminer.conf

    Getting errors : No known USB devices

    Works fine with:
    export DISPLAY=:0
    export GPU_MAX_ALLOC_PERCENT=100
    ./cgminer –scrypt -o stratum+tcp://eu2.multipool.us:7777 -u 123123 -p 123123 -I 13 -g 2 -w 256 –thread-concurrency 8192 –gpu-powertune 20 –temp-cutoff 99 –temp-overheat 95 –temp-target 80 –gpu-fan 40-100 –auto-fan –shaders 2048 –gpu-engine 1013,1075,1075

  3. Per Marius


    ” mine.sh ” :
    export DISPLAY = : 0
    export GPU_MAX_ALLOC_PERCENT = 100
    export GPU_USE_SYNC_OBJECTS = 1
    cd / Hjem/Nedlastinger/cgminer-3.7.2-x86_64-built
    . / cgminer -c cgminer.conf (Correction -c not -n )

    Getting errors : No known USB devices

  4. Cowsniper

    Fantastic! Thanks so much for this guide. I went from a complete noob to knowing some stuff!

    +1 on the donate address. I would definitely send some coins your way!

  5. Cowsniper

    Ok being the noob that I am I’ve encountered a problem. When I run the sh test.sh command it asks me for a password before moving on. Is this right? I did a chmod 755 test.sh. After I enter my password it functions correctly.

    So then I edited /etc/cron.d/saupdate and added the */4 * * * * root sh /home/litecoin/test.sh line and changed that to my directory test.sh was in and triple checked it was right. It isn’t starting on boot (or 4 minutes after or whenever it is supposed to lol)

    Sorry if any of these questions are dumb. Any help is appreciated. Thanks!

  6. Ryan

    Hey Max,
    Thank you so much for taking the time to do all these tutorials for us. I really appreciate it!
    Just one question, I am a little confused about creating the workers. Do I have to create a worker for each GPU or can I use one worker for 4 GPUs?

    Also this part in the code you provided:

    “pools” : [
    “url” : “stratum+tcp://mint.hashstrike.com:3336”,
    “user” : “zedomax.152”,
    “pass” : “xxx”
    “url” : “stratum+tcp://PutYourPoolInfoHere.com:3336”,
    “user” : “zedomax.152”,
    “pass” : “xxx”

    You have the address writing twice because you have 2 GPUs or it doesn’t matter how many GPUs you have, it should always be written twice?

    Thank you so much in advance Max!

    1. Max Lee Post author

      Those are pools, the first one will be used and the rest are used as failovers in case a pool goes down/

      The CGMiner runs all of your GPUs whether 1 or 6 cards, you don’t need to run more than 1 instance.

      You can specify different values for things such as:
      ” GPU memclock “: ” 1500,1500″ ,

      if you have multiple GPUs

  7. L

    Thanks Max !!
    I’m using Byobu instead of screen…
    What do you think of Multiminer for Linux? Would it be useful on your Ubuntu install? with GUI etc…


  8. Dave

    Can I ask why UBUNTU and not BAMT or SMOS?

    I’m almost ready to start my first rig (just waiting to order my gpu’s) and was thinking about BAMT…

  9. L


    Would it be possible to get a tutorial about how to install and set up cgminer for vertcoin and execoin?
    asics and multipool resistant. With the arrival of asics miner this summer, we need to move on before the onslaught…


  10. Dan

    Your A Great Teacher Max, I Could Always Get My Miners Mining However Now, Thanks To You, I Actually Understand Understand What The Code Means. I Hope You Keep Making Videos, Besides Being Very Helpful Your Videos Crack Me Up.
    Your The Man Max

  11. sammer78

    when I type ‘sudo vi .bashrc’ in terminal from my cgminer directory all I get is this
    “.bashrc” [new file]

    what am I doing wrong?

  12. Jeremy

    Can someone please give me the very best setting for Asus Direct CU II R9 290’s. VOltage is locked but they should still be able to get above 830k/h each. I have way to much money tied up in this to be stuck with lower hashrates the the lucky people who got ahold of available saphires and gigabyte R9 290’s. I have 4 rigs of 5 gpu each if that tells you how much money is in my rigs. I want to shoot teh asic people to . Hopefully these new scrypt n is more than just resistant to BS asic. All asics are for are rich people hogging yet another way of getting income. I hate the nerds who created teh asic chips. I hope you all burn in hell. sorry had to rant about the bs. But when you drop as much money as I have into scrypt mining to have asic bomb it like they already did to Bitcoin. RIch asic bastards stay on boitcoin.

  13. Jeremy

    Seed asics are ok but annoying as well for people who have dropped so much into gpu mining that should of stayed gpu mining. But these new ones are just liek teh bitcoin asics. ridiculous.


Leave a Reply

Your email address will not be published. Required fields are marked *