Creating a file to execute terminal commands on mac - bash

I've recently bought a macbook and I am completely new to the whole Mac environment. I'm trying to recreate some automated processes I had on my old windows laptop. So here's my problem:
I use the terminal to download a file from my Google Cloud Storage using the gsutil command:
gsutil cp gs://<bucket>/<file> <destination>
This works and it gets me what I need. My question is: can I make a file that runs this and other commands through the terminal so that I don't have to open up the terminal every time?
I've tried to use the Automator app but it gets way too complicated because Automator doesn't have the same configurations needed that I have already settled in the terminal. I have also tried making a .bs file containing the following code:
#!/bin/sh
gsutil cp gs://<bucket>/<file> <destination>
But this doesn't help me because it just opens up Xcode when I click this file.
There has to be a simple way to make a file which executes some simple terminal commands right? I feel like I am missing something fundamental about macs and linux in general. If you have any idea how I can tackle this, please let me know.
Thanks in advance!

Related

Creating a mac app which calls a shell script, but developing in ubuntu

I have a shell script, and a tarball. The shell script unpacks the tarball, and makes use of the files inside of for performing a task. I need to make this accessible on mac laptops, but in such a way that there is either a .app or .dmg file that when clicked, ultimately calls that shell script. I found several utilities, that can do this (create such an .app file), such as Platypus, or Appify. However, these require Mac to build the file. The thing is, I must package the .app/.dmg file, in an Ubuntu environment.
Is there any good software for creating a dmg or app file which call a shell script when clicked, but such that the software which can be run in Ubuntu (just for the purpose of creating the file)?
This is not an exact answer to your question but an workaround that might be acceptable if you can't find a better solution.
First, a zip file will automatically extract its content if you double click it in OS X so
tar -cvzf your_filename.zip ...
would create a file that can be easily extracted.
Secondly, if you create a shell script that has the extension .command, but otherwise is like any shell script, it can be run from OS X by double clicking on it (by opening a terminal and executing it there), it would mean an extra manual step for the user but like I said, this is a workaround :)
If you create a .command file, remember to make it executable.

How do you go to a local directory in PuTTy?

I'm not used to using PuTTy so I'm not very well versed with all the know hows to use it. So after I log onto the HostName/IP address and log in with my username and ID, there's a local directory /u/SysLab/ where one of the file belongs to me and that's where I'm supposed to do my coding, but I'm not sure how to access it, can anyone tell me how to do this? Me googling "How to go to local directory" yields questions that ask how to transfer files to the server, which isn't what I want to do. I just want to go into the directory and start my coding homework. Can anyone help me?
Did you try cd /u/SysLab?
That should change your current directory to /u/SysLab/ after that you should be able to open the file that you want to work on using some editor e.g. if use Emacs then you could do emacs -nw <yourfile>.
I strongly recommend to first get familiar with (at least) some basic navigation and file handling/editing in the terminal before starting to code.
Assuming your OS is Linux/Unix based, cd (change directory) and the path should work for you: cd /u/SysLab

How to send a file to Desktop with bash script?

I am trying to send a file or folder to Desktop with Linux Command Prompt but I don't know how.
Please tell me what command can I use for this?
The move command mv. Use man mv for more information, as this command is a lot more complex than it seems. With cd Desktop/ you should be able to find your desktop on variations of linux like Mint or Ubuntu. To find your present working directory, as in your current path for the terminal, type pwd. This will give you your directory which will be similar to /home/Desktop.

OS X - Make returning "Nothing to be done for <filename>"

First of all, I would like to apologize if I'm on the wrong stackexchange network, and secondly, sorry if I'm overlooking something simple.
I was moving files from my old hard drive from an old PC when I came across several password protected ZIP Files. However, since those files were a bit old, I forgot the passwords already. I tried every password I could come up with but I still came up empty. After several google searches, I found this tool/utility for Mac OS X that could help me. So I go to the downloads page and download the Mac OSX utility tool and the source code.
However, I am having problems executing the make command for the file. It says on the downloads page:
If you are using linux or another unix, you need to download the source code, uncompress it and type "make" to compile the utility.
So far, what I've tried is
$make /Users/myname/Downloads/aapr-0.01-source/Makefile
I have also tried the other files in the source folder but nothing worked. After that, I'm pretty much blank. I tried double clicking the aapr file in the utility download for Mac (which is a Unix Executable) and it opens a new terminal window displaying the commands and such. Also, doing $aapr [options] [filename] only shows me -bash: aapr: command not found. I also updated XCodes command line tools.
Sorry if I'm missing out on something very basic, I don't usually use the terminal on the OS X.
Try running
cd /Users/myname/Downloads/aapr-0.01-source
make
A Makefile contains rules for building files from other files but it is based on paths and contents, etc. which depend on your current location. So generally you need to be in the directory of the project for it to work.
Edit (copied from my comment):
To execute a command from a specific location (that isn't in the normal $PATH) you need to specify a path for it. So something like /bin/bash or ./aapr (where ./ means the current directory).

How do I run .sh or .bat files from Terminal?

I have a pretty basic problem here, that has happened so haphazardly to me that up until now, I've just ignored it. I downloaded tomcat web server and "Murach's Java Servlets and JSP" book is telling me to navigate to the tomcat/bin directory and start the server my typing in Terminal
$ startup
However, I get the error
-bash: startup: command not found
The relevant files in this directory are startup.sh and startup.bat. Typing both of these returns the same error message
So my questions are, what are .bat and sh files, and how do I run these files? I've read several tutorials for different languages and software programs, and some times when the tutorial says execute a bunch of files in the command line, I get a "command not found" error. Sometimes it works, sometimes it doesn't. This is perplexing to me, so what are some common solutions to solving these sort of "command not found" Terminal problems?
The .sh is for *nix systems and .bat should be for Windows. Since your example shows a bash error and you mention Terminal, I'm assuming it's OS X you're using.
In this case you should go to the folder and type:
./startup.sh
./ just means that you should call the script located in the current directory. (Alternatively, just type the full path of the startup.sh). If it doesn't work then, check if startup.sh has execute permissions.
This is because the script is not in your $PATH. Use
./scriptname
You can also copy this to one of the folders in your $PATH or alter the $PATH variable so you can always use just the script name. Take care, however, there is a reason why your current folder is not in $PATH. It might be a security risk.
If you still have problems executing the script, you might want to check its permissions - you must have execute permissions to execute it, obviously. Use
chmod u+x scriptname
A .sh file is a Unix shell script. A .bat file is a Windows batch file.
Type bash script_name.sh or ./script_name in linux terminal. Before using ./script_name make you script executeable by sudo chmod 700 script_name and type script_name.bat in windows.
Drag-And-Drop
Easiest way for a lazy Mac user like me: Drag-and-drop the startup.sh file from the Finder to the Terminal window and press Return.
To shutdown Tomcat, do the same with shutdown.sh.
You can delete all the .bat files as they are only for a Windows PC, of no use on a Mac to other Unix computer. I delete them as it makes it easier to read that folder's listing.
File Permissions
I find that a fresh Tomcat download will not run on my Mac because of file permission restrictions throwing errors during startup. I use the BatChmod app which wraps a GUI around the equivelant Unix commands to reset file permissions.
Port-Forwarding
Unix systems protect access to ports numbered under 1024. So if you want to use port 80 with Tomcat you will need to learn how to do "port-forwarding" to forward incoming requests to port 8080 where Tomcat listens by default. To do port-forwarding, you issue commands to the packet-filtering (firewall) app built into Mac OS X (and BSD). In the old days we used ipfw. In Mac OS X 10.7 (Lion) and later Apple is moving to a newer tool, pf.
Based on IsmailS' comment the command which worked for me on OSX was:
sudo sh ./startup.sh
On windows type either startup or startup.bat
On unix type ./startup.sh
(assuming you are located in tomcat/bin directory)
Batch files can be run on Linux. This article explains how (http://www.linux.org/threads/running-windows-batch-files-on-linux.7610/).
Type in
chmod 755 scriptname.sh
In other words, give yourself permission to run the file. I'm guessing you only have r/w permission on it.
add #!bin/bash on top of the your .sh file
sudo chmod +x your .sh file
./your.sh file
these steps work~
My suggestion does not come from Terminal; however, this is a much easier way.
For .bat files, you can run them through Wine. Use this video to help you install it: https://www.youtube.com/watch?v=DkS8i_blVCA. This video will explain how to install, setup and use Wine. It is as simple as opening the .bat file in Wine itself, and it will run just as it would on Windows.
Through this, you can also run .exe files, as well .sh files.
This is much simpler than trying to work out all kinds of terminal code.
I had this problem for *.sh files in Yosemite and couldn't figure out what the correct path is for a folder on my Desktop...after some gnashing of teeth, dragged the file itself into the Terminal window; hey presto!!

Resources