My Beginner BitBurner Notes, Batch Scripts and Deployments

Introduction

Welcome!

I am a lifetime artist with over 3 decades of experience in:

-Digital Painting and Graphic Design

-Music Production

-Lyricism

-Video Editing

I decided recently that I would make my own video game universe, complete with lore and stories so that I could begin to build games.

Which brings me to BitBurner!

I am obviously a novice, but this guide is an exact copy of the .txt notes I created while learning the game!

Hoping you find some use from this!

Enjoy!

Important things to know:

//Double "//" are used to indicate important notes/details in scripts.

//The script will come first, and the notes will be below the script

//Quotation marks ("") in the commands below, represent a place in the command where you should //insert your own definitions for server names and script names

//For example

run "YourCustomScript.exe"

//is not an actual command.

//if you have a script you have created, and it is saved as NUKE.exe

//the command above would be

run NUKE.exe

//Notice the quotation marks are left out.

Tutorial Commands, In Order

This section is just for the commands that you use while working your way through the tutorial of BitBurner!

///------\\\

=========

Tutorial Commands

=========

\\\------///

help

//list of all available Terminal commands

ls

//shows files on the computer

scan

//shows all available network connections

scan-analyze

//shows more detailed information about each server

scan-analyze 2

//see information about all servers that are up to two nodes away

connect "server name"

//Connect to designated server

analyze

//show useful information about hacking the server

run NUKE.exe

//root access script execution

run "YourCustomScript.exe"

//run designated script

hack

//attempts hacking current server

grow

//increases $ stored on server

weaken

//weaken server security level

nano

//create a new script

nano "YourCustomScript.exe"

//edit existing script

free

//check free ram on selected machine

tail "YourCustomScript.exe"

//dump script logs

kill "YourCustomScript.exe"

//stops a script from running

The "help" Command List And Explanation Function

///------\\\

=========

Help Command

=========

\\\------///

// typing "help" into your command line will dump the LONG list below

alias [-g] [name="value"] Create or display Terminal aliases

analyze Get information about the current machine

backdoor Install a backdoor on the current machine

buy [-l/-a/program] Purchase a program through the Dark Web

cat [file] Display a .msg, .lit, or .txt file

cd [dir] Change to a new directory

check [script] [args...] Print a script's logs to Terminal

clear Clear all text on the terminal

cls Same as 'clear' command

connect [hostname] Connects to a remote server

cp [src] [dest] Copy a file

download [script/text file] Downloads scripts or text files to your computer

expr [math expression] Evaluate a mathematical expression

free Check the machine's memory (RAM) usage

grep [opts]... pattern [file]... Search for PATTERN (string/regular expression) in FILE and print

results to terminal [-O] [target file]

grow Spoof money in a servers bank account, increasing the amount

available.

hack Hack the current machine

help [command] Display this help text, or the help text for a command

history [-c] Display the terminal history

home Connect to home computer

hostname Displays the hostname of the machine

kill [script/pid] [args...] Stops the specified script on the current server

killall Stops all running scripts on the current machine

ls [dir] [--grep pattern] Displays all files on the machine

lscpu Displays the number of CPU cores on the machine

mem [script] [-t n] Displays the amount of RAM required to run the script

mv [src] [dest] Move/rename a text or script file

nano [files...] Text editor - Open up and edit one or more scripts or text files

ps Display all scripts that are currently running

rm [OPTIONS]... [FILE]... Delete a file from the server

run [script] [-t n] [--tail] Execute a program or script

[--ram-override n] [args...]

scan Prints all immediately-available network connections

scan-analyze [d] [-a] Prints info for all servers up to d nodes away

scp [files...] [server] Copies a file to a destination server

sudov Shows whether you have root access on this computer

tail [script] [args...] Displays dynamic logs for the specified script

top Displays all running scripts and their RAM usage

unalias [alias name] Deletes the specified alias

vim [files...] Text editor - Open up and edit one or more scripts or text files in vim

mode

weaken Reduce the security of the current machine

wget [url] [target file] Retrieves code/text from a web server

// I'm sure a lot of that doesnt make sense.

// But that's OK! You can use the "help" command to get more information!

// I had trouble figuring out the "alias" command, so we will use it as an example!

In your command line, type:

"help alias"

It will dump this into your window:

Usage: alias [-g] [name="value"]

Create or display aliases. An alias enables a replacement of a word with another string.

It can be used to abbreviate a commonly used command, or commonly used parts of a command. The NAME of an alias defines the word that will be replaced, while the VALUE defines what it will be replaced by.

For example, you could create the alias 'nuke' for the Terminal command 'run NUKE.exe' using the following command line entry:

alias nuke="run NUKE.exe"

Then, to run the NUKE.exe program you would just have to enter 'nuke' in Terminal rather than the full command.

It is important to note that 'default' aliases will only be substituted for the first word of a Terminal command.

For example, if the following alias was set:

alias worm="HTTPWorm.exe"

and then you tried to run the following terminal command:

run worm

This would fail because the worm alias is not the first word of a Terminal command. To allow an alias to be substituted anywhere in a Terminal command, rather than just the first word, you must set it to be a global alias using the -g flag, like this:

alias -g worm="HTTPWorm.exe"

Now, the 'worm' alias will be substituted anytime it shows up as an individual word in a Terminal command.

Entering just the command 'alias' without any arguments prints the list of all defined aliases in the reusable form 'alias NAME=VALUE' on the Terminal.

The 'unalias' command can be used to remove aliases.

NOTE: The --all alias is reserved for removal.

See!! Eazy!

Simple, Sample Looped Hacking Script

///------\\\

=================

Sample Hack Script

=================

\\\------///

//The "await" keyword is needed for hack() / grow() / weaken() because these commands take time to //execute, unlike the others. If you forget to await these commands, you will get an exception

//saying you tried to do multiple things at once, because your code will immediately finish the //function call without waiting for the operation to be done. Also important is that await can

//only be used in functions marked async (note that main() is marked async).

/** @param {NS} ns */

export async function main(ns) {

const target = "n00dles";

// Defines the "target server", which is the server that we're going to hack. In this case, it's "n00dles"

const moneyThresh = ns.getServerMaxMoney(target);

// Defines how much money a server should have before we hack it. In this case, it is set to the maximum amount of money.

const securityThresh = ns.getServerMinSecurityLevel(target);

// Defines the minimum security level the target server can have. If the target's security level is higher than this, we'll weaken it before doing anything else

if (ns.fileExists("BruteSSH.exe", "home")) {

ns.brutessh(target);}

// If we have the BruteSSH.exe program, use it to open the SSH Port

// on the target server

ns.nuke(target);

// Get root access to target server

while(true) {

if (ns.getServerSecurityLevel(target) > securityThresh) {

// If the server's security level is above our threshold, weaken it

await ns.weaken(target);

} else if (ns.getServerMoneyAvailable(target) < moneyThresh) {

// If the server's money is less than our threshold, grow it

await ns.grow(target);

} else {

// Otherwise, hack it

await ns.hack(target);

}

}

}

// Infinite loop that continously hacks/grows/weakens the target server

Multi-Threading

///------\\\

=================

Multi-threading

=================

\\\------///

mem "YourCustomScript.js"

// This command: Checks a scripts RAM usage on a selected server

// You can also view the script RAM usage at the bottom of the "Script Editor"

//the "early-hack-template.js" that is provided by the tutorial uses 2.6GB of RAM, and can

//run 6 threads on a 16GB server.

//Now, to run our script on all of these servers, we have to do the following:

//1. Use the scp command to copy our script to each server.

//2. Use the connect command to connect to a server.

//3. Use the run command to run the NUKE.exe program and gain root access.

//4. Use the run command again to run our .

//5. Repeat steps 2-4 for each server.

//Here's the sequence of Terminal commands and scripts I used in order to achieve this.

//The format is: "scp [scripts/files...] [server]"

//KEEP IN MIND: the script/file name is the name of MY scripts. Use your own.

//KEEP IN MIND: the server names are custom to your game.

Use the "scan" or "scan-analyze" commands to find servers you can use.

Look for servers that have high ram and do not require any open ports in order to run NUKE.exe

home

scp hack1tem.js n00dles

scp hack1tem.js foodnstuff

connect n00dles

run NUKE.exe

run hack1tem.js -t 1

home

connect foodnstuff

run NUKE.exe

run hack1tem.js -t 6

//When running our scripts with the "run early-hack-template.js -t 6" command, the "-t 6" //specifies that the should be run with 6 threads.

Bulk Scripts

///------\\\

=================

Bulk Scripts

=================

\\\------///

//Sometimes, you might need to kill all scripts on all of your servers, so you can deploy new ones

//I call this script "ServerKill.js"

/** @param {NS} ns */

export async function main(ns) {

const targets = ["n00dles", "foodnstuff", "sigma-cosmetics", "joesguns", "hong-fang-tea", "harakiri-sushi"];

// Define the target servers

for (const target of targets) {

// Loop through each target server

if (ns.hasRootAccess(target)) {

// Check if we have root access to the target server

ns.killall(target);

// Kill all scripts running on the target server

ns.tprint(`Killed all scripts on ${target}`);

} else {

ns.tprint(`No root access on ${target}. Cannot kill scripts.`);

}

}

}

//Sometimes you might need to clean up and remove bad scripts from your servers

//I call this script "RemoteScriptDelete.js"

/** @param {NS} ns */

export async function main(ns) {

// Get all servers

const servers = scanAllServers(ns);

for (const server of servers) {

if (ns.hasRootAccess(server) && server !== "home") {

// Check if you have root access and exclude "home"

ns.tprint(`Deleting scripts on ${server}...`);

const scripts = ns.ls(server);

// Get the list of scripts on the server

for (const script of scripts) {

// Exclude the script that is currently running this main script

if (script !== "deleteScripts.js") {

// Delete the scripts

await ns.rm(script, server);

ns.tprint(`Deleted ${script} from ${server}`);

}

}

} else if (server === "home") {

ns.tprint(`Skipping home server.`);

} else {

ns.tprint(`No root access on ${server}. Skipping...`);

}

}

}

/** @param {NS} ns */

function scanAllServers(ns) {

let serversToScan = ["home"];

let scannedServers = [];

while (serversToScan.length > 0) {

let server = serversToScan.pop();

if (!scannedServers.includes(server)) {

scannedServers.push(server);

let connectedServers = ns.scan(server);

for (let connected of connectedServers) {

if (!scannedServers.includes(connected)) {

serversToScan.push(connected);

}

}

}

}

return scannedServers;

}

Deployments And Payloads

///------\\\

=================

Deployments & Payloads

=================

\\\------///

//Deployment Scripts can be used to target multiple servers, send a 2nd script, known as a payload, to each of them and execute the second script

//Im sure they can do much more, but I am n00b

//Deployment Script

//A script that copies and executes a 2nd script "hack2tem.js" to world based servers with variety in multi-threading

//I call this one "GroupHack2.js"

/** @param {NS} ns */

export async function main(ns) {

//Define the target servers and the # of threads to run on each

const targets = {

"n00dles": 1,

//n00dles has 4GB ram,

//hack2tem.js uses 2.65GB ram per thread

"foodnstuff": 6,

"sigma-cosmetics": 6,

"joesguns": 6,

"hong-fang-tea": 6,

"harakiri-sushi": 6

//The other servers all have 16GB ram,

//hack2tem.js still uses 2.65GB per thread

};

for (const [target, threadCount] of Object.entries(targets)) {

if (ns.hasRootAccess(target)) {

// Check if you have root access to the target server

ns.killall(target);

// Kill any scripts currently running on the target server

ns.tprint(`Killed all scripts on ${target}`);

await ns.scp("hack2tem.js", target);

// Copy the hack2tem.js script to the target server

ns.exec("hack1tem.js", target, threadCount);

// Execute the script on the target server with the specified number of threads

ns.tprint(`Deployed hack1tem.js to ${target} with ${threadCount} threads`);

} else {

ns.tprint(`No root access on ${target}`);

}

}

}

//Payload Script

//The 2nd script is deployed to designated servers by the 1st script "GroupHack2.js"

//I call this script "hack2tem.js"

/** @param {NS} ns */

export async function main(ns) {

const target = ns.getHostname();

// Defines the target server, which is the server that this script is run on

const moneyThresh = ns.getServerMaxMoney(target);

// Defines how much money a server should have before we hack it

// In this case, it is set to the maximum amount of money.

const securityThresh = ns.getServerMinSecurityLevel(target);

// Defines the minimum security level the target server can have.

// If the target's security level is higher than this, we'll weaken it before doing anything else.

if (ns.fileExists("BruteSSH.exe")) {

ns.brutessh(target);

// If we have the BruteSSH.exe program, use it to open the SSH Port on the current server

}

ns.nuke(target);

// Get root access to target server

let threads = 2; // Default value

// Determine the number of threads based on the target server

switch (target) {

case "n00dles":

threads = 1;

break;

case "foodnstuff":

case "sigma-cosmetics":

case "joesguns":

case "hong-fang-tea":

case "harakiri-sushi":

threads = 6;

break;

default:

ns.tprint(`No specific thread allocation for ${target}. Defaulting to ${threads} threads.`);

// Assign the appropriate number of threads for each target server

}

while (true) {

if (ns.getServerSecurityLevel(target) > securityThresh) {

// Infinite loop that continuously hacks/grows/weakens the target server

await ns.weaken(target, { threads });

} else if (ns.getServerMoneyAvailable(target) < moneyThresh) {

// If the server's security level is above our threshold, weaken it

await ns.grow(target, { threads });

// If the server's money is less than our threshold, grow it

} else {

await ns.hack(target, { threads });

// Otherwise, hack it

}

await ns.sleep(100);

// Sleep for a brief moment to avoid overloading the server

}

}

Source: https://steamcommunity.com/sharedfiles/filedetails/?id=3338266866					

More Bitburner guilds