MACFUSE + XML to JSON | with code splitter + pip

sshsf + Macfuse

sshsf

https://github.com/libfuse/sshfs
https://eud.gsfc.nasa.gov/David.Friedlander/my_docs/fuse_for_macs.html
https://sbgrid.org/corewiki/faq-sshfs.md


https://sbgrid.org/corewiki/faq-sshfs.md

https://sbgrid.org/corewiki/faq-sshfs.md

Setting up sshfs on OS X (Mac) systems

Installation requires administrative privileges.

Prior to installing, you should make sure that you can SSH with keys

  1. Download OSXFuse (dmg) (pkg) from http://osxfuse.github.io
  2. Open OSXFuse dmg , run installer
  3. Download SSHFS (pkg) from from http://osxfuse.github.io
  4. Run SSHFS installer pkg
  5. Create a folder to access the remote filesystems (aka a mount point): mkdir /sshfs/
Mounting remote filesystems with sshfs
sshfs username@remotesystem:/full/path/to/directory /mount/point

For example, sshfs meyer@schl15:/nfs/userdocs/ps/meyer ~/userdocs/home would use schl15 as a host to access the directory /nfs/userdocs/ps/meyer (in other words, that user's NFS home directory).

You should mount sshfs via a directory in your home directory. Just remember to specify the PATH to the directory.

OS X (Mac) helpful hints

As of OSX 10.15 Catilina we are not recommending to create mounts in the root path or / of the file system.

An example of mounting from OSX on your local system is as follows –

mkdir ~/userdocs
/usr/local/bin/sshfs oconnor@xtal200.harvard.edu:/nfs/userdocs /Users/oconnor/userdocs -o volname=userdocs,reconnect,ServerAliveInterval=15,ServerAliveCountMax=3,idmap=user,auto_xattr,dev,suid,defer_permissions,noappledouble,noapplexattr

You should mount one complete filesystem from the remote site, so this would be anything listed in /nfs for example. This avoids local Apple Finder issues. We give the volume a name volname=userdocs (shows mount point on your desktop), add some additional options for server connections, etc. If you are using an key-based-ssh you would add it's path to the IdentityFile paramater – adding ,IdentityFile=$HOME/.ssh/id_rsa to the end of the line.

Unmounting remote filesystems

On occasion the mount may become stuck or unresponsive you can force unmount via – diskutil umount force /Users/oconnor/userdocs

Using helper script

We created a 'helper' script available that can be used with sshfs_nfs.app for mac to automount at login. The app is simply a wrapper for sshfs-helper.sh and assumes the script exists in your home folder.

If the mounts become stuck just rerun to reattach shares.

scp $USER@xtal200.harvard.edu:/net/cronus/cmcd1/arc/shared/sshfs-helper.sh .

or copy the whole set –

rsync -rlptD $USER@xtal200.harvard.edu:/net/cronus/cmcd1/arc/shared/sbgrid-sshfsfiles.zip .

The script will create a file in your home folder called .sshfs-mounts

You can add or change any number of mounts that sshfs-helper.sh –

To open – open .sshfs_mounts then edit in textedit.app.

An example – #USER@HOST REMOTE_FOLDER LOCAL_FOLDER | empty local folder must exist oconnor@sshfs.sbgrid.org /nfs/userdocs /Users/oconnor/userdocs jo232@transfer.o2.hms.harvard.edu /home/myfolder /Users/oconnor/o2home

After it is working you can add a shortcut into your dock by navigating to your home folder on your Mac open ~ and then dragging the sshfs_nfs.app into your dock. If you need to reconnect to the shares just press the app and it will connect or reconnect. For additional folders you must create the destination folder like – mkdir ~/o2home

After it is working you can add a shortcut into your dock by navigating to /Users/Shared/ on your Mac open /Users/Shared and then dragging the sshfs_nfs.app into your dock. If you need to reconnect to the shares just press the app and it will connect or reconnect.

 


May have to ssh into bluehost first – then connect via sshsf

sshfs username@hostname:/remote/directory/path /local/mount/point

sshfs username@xxx.xxx.xxx.x:/home3/xxxxxx/public_html/ ~/desktop/sshsf/bluehost -o reconnect,idmap=user,password_stdin,dev,suid
alias sshfs_bluehost ‘sshfs username@xxx.xxx.xxx.x:/home3/xxxxxx/public_html/ ~/desktop/sshsf/bluehost -o reconnect,idmap=user,password_stdin,dev,suid’

In this command, /remote/directory/path is the path to the desired folder on the remote server that you have access to. (Alternatively, you can just use a forward slash to mount the root directory.) The /local/mount/point is the full path on your current system to the new mount folder. For example, if you want to mount the entire root file system from the remote computer at a folder called “mount” in your home directory, then you would run a command similar to the following:

sshfs username@hostname:/ ~/mount

shortcut

tcsh version:
alias my_econ ‘sshfs bobama@westwing.whitehouse.gov:/data/economic $HOME/my_remote_mount’

re-connect option

You can run sshfs with the “reconnect” option. We use sshfs with PAM/automount to share server files for each workstation in our network. We use -o reconnect as parameter for sshfs, mostly because our users suspended their computers and on wake sshfs would not reconnect (or respond, or anything).

For example:

sshfs mvaldez@192.168.128.1:/home/mvaldez/REMOTE /home/mvaldez/RemoteDocs -o reconnect,idmap=user,password_stdin,dev,suid

Just a note, if the remote computer is really down, sshfs may become unresponsive for a long time.

HOW TO MOUNT DISKS WITH SSHFS
Create a mount point. (Either do this once in a permanent location or create something under /tmp.)
mkdir $HOME/my_remote_mount
The name can be anything you want, but don’t have spaces in the name.
Simple version of the mount:

sshfs remote_username@remote_host:/path/to/desired/dir $HOME/my_remote_mount

e.g.,
sshfs bobama@westwing.whitehouse.gov:/data/economic $HOME/my_remote_mount

If your username is the same locally and remotely, you can omit it, as you would for plain ssh:
sshfs westwing.whitehouse.gov:/data/economic $HOME/my_remote_mount

HOW TO UNMOUNT DISKS
The man page for sshfs says to use fusermount -u usermount. This doesn’t work for Macs because the fusermount command does not exist! Fortunately, there are various easy ways to unmount the disk:

From the command line:
umount /path/to/mount/point

e.g.,
umount $HOME/my_remote_mount

From the Finder, drag the remote disk to the Trash
From the Finder, right-click (or control-click) on the remote disk and Eject.

CREATE ALIASES TO EASE FUTURE USE
Once you have your sshfs setup the way you like it, it is highly recommended to capture that into an alias that you place in your .cshrc or .bash_profile startup file. It could be something like this:

tcsh version:
alias my_econ ‘sshfs bobama@westwing.whitehouse.gov:/data/economic $HOME/my_remote_mount’

bash version:
alias my_econ=’sshfs bobama@westwing.whitehouse.gov:/data/economic $HOME/my_remote_mount’



Pip – to break up code

https://www.geeksforgeeks.org/how-to-install-pip-in-macos/

Before we start with how to install pip for Python on macOS, let’s first go through the basic introduction to Python. Python is a widely-used general-purpose, high-level programming language. Python is a programming language that lets you work quickly and integrate systems more efficiently.

PIP is a package management system used to install and manage software packages/libraries written in Python. These files are stored in a large “on-line repository” termed as Python Package Index (PyPI).

pip uses PyPI as the default source for packages and their dependencies. So whenever you type:

pip install package_name

pip will look for that package on PyPI and if found, it will download and install the package on your local system.

Download and Install pip:

pip can be downloaded and installed using command-line by going through the following steps:

 

 

  • Download the

    get-pip.py

    file and store it in the same directory as python is installed.

    or

    Use the following command to download pip directly,

    curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
    
  • Now execute the downloaded file using below command

    python3 get-pip.py
    

    and wait through the installation process.

  • Voila! pip is now installed on your system.

Verification of the Installation process:

One can easily verify if the pip has been installed correctly by performing a version check on the same. Just go to the command line and execute the following command:

pip3 --version

Attention geek! Strengthen your foundations with the Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

 

 

 

 

Splittling large xml files

 

Splitting XML file on Mac

To split files on your Mac, you need to use a different and simpler script written in python called ‘mainSplit’.

Now go to the intro page and at the botton of the page, download mainSplit.py script. Make sure to download the file in (.py) extension and not (.txt) extension.

Once downloaded, open Terminal console that’s available from Application > Utilities folder on your Mac and enter the following line:

python mainScript.py

Running the line will open a small window of ‘WordPress XML Splitter’. Click on button ‘Browse File’ to select the XML file you want to split, and then select the folder you want the file to be saved to by clicking on ‘Browse Dir.’

When ready, click the ‘Start’ button and the processing will start immediately.

To check the split files, go to the directory you have selected earlier, and you will see a collection of files, not more than 2Mb in size each.

Conclusion

Both solutions on Mac and Windows are pretty much similar, although you are using different programs and scripts. The process is simple and fast, making your migration process easy with WordPress. There are many other ways to backup your WordPress files, but this approach of splitting XML files manually does not take a lot of your time.

 

 

Converting XML to JSON

 

How to Convert XML to JSON on the Command Line

XML is complicated, and parsing it natively is fairly hard, even with scripting languages. Luckily, there’s a utility that can convert XML to JSON, which is easier to work with, both in scripts and on the command line.

Use the xq Utility

You’ll want to use a custom made utility for this, rather than trying to parse it with something like regex, which is a bad idea. There’s a utility called xq that is perfect for this task. It’s installed alongside yq, which works for YAML. You can install yq from pip:

pip install yq

Under the hood, this utility uses to handle working with JSON, so you’ll need to download the binary, and move it to somewhere on your PATH (/usr/local/bin/ should work fine).

Now, you’ll be able to parse XML input by piping it into xq:

cat xml | xq .

The . operator means you want to convert all of the XML to JSON. You can actually use full jq syntax here to select sub-elements, which you can read our guide on.

You can also output xq‘s response as XML with the -x flag:

xq -x

This lets you use jq‘s selection syntax to parse XML while keeping it in XML form. Though it doesn’t seem to be able to convert the other way, as xq still wants XML syntax in.

One Problem With XML to JSON Conversion

XML to JSON isn’t a perfect conversion—in XML, the order of the elements can matter, and keys can be duplicated. A document like:

<e>
  <a>some</a>
  <b>textual</b>
  <a>content</a>
</e>

Would produce an error if translated outright to JSON, because the a key exists twice. So, it’s converted to an array, which does break the order. xq returns the following output for that bit of XML:

{
  "e": {
    "a": [
      "some",
      "content"
    ],
    "b": "textual"
  }
}

Which is technically correct, just not ideal in all situations. You’ll want to double-check and make sure your XML conversion has no issues.

 

Scroll to Top