Script Name: mega_upload_file.sh

Description

This script will Upload file to a folder for a Mega.nz account.


Configuration

There are configuration settings that can go into .mega_scriptsrc for section [MEGA_UPLOAD_FILE]

See Configuration file.

Parameters

-p

Required: The path to upload on Mega.nz.

-l

Requited: The local file to upload onto Mega.nz.

-i

Optional: The configuration file to use that contain the credentials for the Mega.nz account you want to access.
See Set up .megarc.

-o

Optional: The Log file to log to results of running mega_upload_file.sh.
Can be value of "t" in which case results are outputted to the terminal window
Can be value of "s" in which case no results are written to a log file or terminal window.
Defaults to /var/log/mega_put_file.log (requires script be run as root)
Setting -o option overrides the LOG option of [MEGA_UPLOAD_FILE] of Configuration file.

-d

Optional: Date of Log in the format of yyyy-mm-dd-hh-mm-ss. This will be used as the date stamp in the log file
Example: 2018-06-21-14-31-22
If -o is set to "s" then -d will be ignored.

-h

Optional: Display Script help

-v

Optional: Display script version


Possible Codes returned from Script

Code

Definition

0

Normal Exit. No Errors Encountered.

3

No write privileges to create log file.

4

Log file exist but no write privileges.

100

There is another mega process running. Can not continue.

103

megaput not found. Megtools requires installing or properly configure MT_MEGA_PUT option of .mega_scriptsrc to point to the megaput location

104

No argument supplied for Mega Server Path

110

No mega server path specified

111

Optional argument -i was passed in but the config can not be found or we do not have read permissions

112

The file to upload does not exist or can not gain read access.

116

The file to upload is not actually a file. Could be non existent or a directory.


Remarks

Never pass in the directory Root to mega_upload_file.sh as the frist part of the path.

For -p -p '/MyPath/myfile' is fine; however, -p '/Root/MyPath/myfile' will fail.


-p  Path to upload must exist on mega. for this reason it might be better to run mega_mkdir.sh before running mega_upload_file.sh.

That way if the path does not exist it will get created first.


If -i is omitted then you must have .megarc set in the current users home directory.


-o is optional but useful when calling mega_upload_file.sh from a master script such as mega_db_save_upload.sh (source).


-d is optional but also useful when calling mega_upload_file.sh from a master script such as mega_db_save_upload.sh (source). By passing Log and Date to mega_upload_file.sh then one log file will contain the same datestamp for all of the other called related scripts.


If the name of this file "mega_upload_file.sh" is change for any reason then it needs to be reflected in the configuration file. See Configuration File.

Example

The following examples assume the path for upload already exit on Mega.nz. Run mega_mkdir.sh before running mega_upload_file.sh. If your not certain the path already exist on Mega.nz.


# /bin/bash /usr/local/bin/mega_upload_file.sh -p '/example/test' -l ~/hello.txt; echo $?
0


Checking the log file we can see the results


# cat /var/log/mega_upload_file.log
2018-06-06-10-29-19 MEGA PUT: Uploading '/root/hello.txt' to directory '/Root/example/test' on MEGA.nz.
2018-06-06-10-29-19 MEGA PUT: Upload result: [0KUploaded hello.txt
2018-06-06-10-29-19 MEGA PUT: MEGA Upload Done


Example

In the following example the hello.txt file is uploaded to Mega.nz to a different name then the original file. The output is directed to the terminal and not a log by setting -o to "t"


# /bin/bash /usr/local/bin/mega_upload_file.sh -p '/example/test/hello world.txt' -l ~/hello.txt -o t
2018-06-06-10-35-04 MEGA PUT: Uploading '/root/hello.txt' to directory '/Root/example/test/hello world.txt' on MEGA.nz.
2018-06-06-10-35-04 MEGA PUT: Upload result: [0KUploaded hello.txt
2018-06-06-10-35-04 MEGA PUT: MEGA Upload Done


We can confirm using mega_dir_file_exist.sh.


# /bin/bash /usr/local/bin/mega_dir_file_exist.sh -p '/example/test/hello world.txt'; echo $?
3


We can also see the results by running megals of megatools.


# megals -l "/Root/example/test"
MAECWBLK    xsxPDMASKE4 1             - 2018-06-06 10:11:56 /Root/example/test
xEdjBbzY    xsxPDMASKE4 0            12 2018-06-06 10:35:07 /Root/example/test/hello world.txt
oJchXI4T    xsxPDMASKE4 0            12 2018-06-06 10:29:22 /Root/example/test/hello.txt


Related

Set up .megarc

mega_db_save_upload.sh Latest Source.