Bash

Bash: SSH with Tunnel

Syntax

ssh user@remoteHost.com -L 81:remoteHost:81

ssh user@192.168.0.112 -L 81:r192.168.0.112:81

Script

#!/bin/bash
function ssh-tunnel-112(){
        export $(grep -v '^#' .env | xargs)
        echo "ssh to .112:8081 to pi:3001"
        sudo ssh me@192.168.0.112 -L 8081:pi:3001
}
echo "creating tunnel on port 81"
ssh-tunnel-112

 

Tags

PHP: Passing Arguments from Bash To PHP

Resources:

Shell

echo "Testing destination dir -" $ytuDest

PHP Main

/*
 * Start of PHP CLI Script
 */
//require_once '/home/silosix/git/phpunitwebdriver/src/Shell/YtdlWrapper.php';
//require_once '../Shell/YtdlWrapper.php';
print "Downloading YT Videos: START"."\n";
print "parsing arguments"."\n";
parse_str($argv[2],$output);
var_dump($argv);
var_dump($output);
$ytuDest = $output['ytuDest'];
print "ytuDest=" .
Tags

Linux: Bash: /bin/bash^M: bad interpreter: No such file or directory

 

/bin/bash^M: bad interpreter: No such file or directory

the ^M is the key to the solution here.... invalid line endings

Windows & Linux use different EOL encoding...

in Notepad++ open the file and then select one according to the runtime host OS

  • Edit > EOL Conversion > Linux(LF)
  • Edit > EOL Conversion > Windows (CR LF)
  • Edit > EOL Conversion > Macinstosh (CR)
Tags

Linux: Bash: Echo Commands

echo Options


 Options      Description
 -n      do not print the trailing newline.
 -e      enable interpretation of backslash escapes.
 \b      backspace
 \\      backslash
 \n      new line
 \r      carriage return
 \t      horizontal tab
 \v      vertical tab
Tags

Pi: USB HDD Setup

List Disks

sudo lsblk -o UUID,NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL,MODEL

mdp@pi:/ $ sudo lsblk -o UUID,NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL,MODEL
[sudo] password for mdp:
UUID                                 NAME        FSTYPE   SIZE MOUNTPOINT           LABEL   MODEL
                                     sda                   29G                              Storage_Device
d486f62b-1ad3-4140-ab53-129665994877 └─sda1      xfs       29G /media/mdp/PiDrive   PiDrive
                                     sdb                465.8G                              MQ01ABD050V
409821DB9821D068                     └─sdb1      ntfs   465.8G /media/silosix/W[500 W[500   
                                     mmcblk0             59.5G                              
3FFE-CDCA                            ├─mmcblk0p1 vfat     256M /boot                boot    
3122c401-b3c6-4d27-8e0d-6708a7613aed └─mmcblk0p2 ext4    59.2G /                    rootfs

Tags

Bash: Changing Owner of a folder

 

If you want to change the user owning this file or directory (folder), you will have to use the command chown. For instance, if you run

sudo chown username: myfolder

the user owning myfolder will be username. Then you can execute

sudo chmod u+w myfolder

to add the write permission to the username user.

But if you want to add this user to the group associated with "myfolder", you can run

sudo usermod -a -G groupname username

and then execute

sudo chmod g+w myfolder

to add the write permission to the group.

Tags
Subscribe to Bash