How do I save a file Withou extension in linux? - linux

Recently i was trying to save a file as "ssh" for my raspberry pi, with which i'm having trouble configuring. the only way i can save a file without extension is on windows. is there any way i can do that on linux so i won't need to keep changing O.S all the time?

Not sure what you're using but unix (and linux by extension (no pun intended)) don't even have the concept of an extension on a filename. It's all just a filename and there can be dots in them. The 8.3 thing came from MS-DOS ...
So to create a file called "ssh" just name it that, no dot no extension and you're done.
E.g.:
$ echo "hello world" > ssh
or
$ vi ssh
etc. all are capable of creating a file called ssh (take care with the first one, it'll overwriting existing files).
Also if you have a file salled let's say "ssh.whatever", you can rename it with
$ mv ssh.whatever ssh
If you have a tool that's not allowing you to create a file without an extension on a unix system, odds are it's not something that was made by somebody who knows what they were doing.

Related

Configuration file pulled from S3 segfaults OpenSwan

I'm trying to configure OpenSwan, an open source IPsec solution written in C.
I have a script to download a configuration file ipsec.conf on an Amazon Linux EC2 that was created on my Macbook and uploaded to S3.
When I start the ipsec service, it segfaults.
Curiously, if I open the configuration file with VIM, make no changes, and simply write/quit, it works. This lends me to believe somehow the file has some weird characters/formatting.
I know of dos2unix, which I ran on the configuration file but that did not prevent the segfault.
I'm wondering what exactly VIM is doing when I write/quit. I could script that operation on my configuration file after pulling it. Or anything else that would help me understand what's going on.
First, try to open the file with vim, then exit vim (:q) without having saved the file before. If vim says File modified since last complete write; write or use ! to override., this means that this is not something that vim does when write/quit that changes your file, but that this is something that vim does when it opens the file. And this is the most common case.
Vim parses the input file depending on the locale, and if some characters can not be understood according to the locale, vim may forget them. So, when saving the file, those characters will be removed.
Now, use vim to save your file as ipsec-ok.conf.
And run the following command:
bash -c 'diff <(od -xa ipsec.conf) <(od -xa ipsec-ok.conf)'
This will display the differences between the original file and the one that works with OpenSwan. In ascii and hexadecimal formats. This way, you will find the unsupported characters that make OpenSwan dump a core.

Cygwin bash files

About a year ago, I created a couple text files called "compile" and "pull." When I go into a cygwin prompt and type those names and hit enter (basically use them as a command), the cygwin terminal runs what is in those text files. For instance here is the contents of one:
git checkout master
git checkout -- .
I don't even remember how I did this. I'm pretty sure this is not a bash script.
I do remember that I had to not just create the file in notepad but also perform some linux command line operation on it, in order to use it. Once I did that I could basically use the file as a command.
In *nix, you have to make a file executable in order to be able to run it:
chmod u+x file
You also need to add the path to the file to the PATH variable
PATH=$PATH:/path/to/the/file
or, add . to always scan the current directory for commands (it's considered unsecure, though):
PATH=$PATH:.

Shell script to download file from UNIX system directory

Can any one help me writing a shell script to Download files from Linux/UNIX system?
Regards
On UNIX systems, such as Linux and OSX, you have access to a utility called rsync. It is installed by default and is the tool to use to download files from another UNIX system.
It is a drop-in replacement for the cp (copy) command, but it is much more powerful.
To copy a directory from a remote system to yours, using SSH, you would do this:
rsync username#hostname:path/to/dir .
(notice the dot at the end, this means 'place everything here please', you can also give the name of the local dir where the files should be placed.)
To download only some specific files, use this:
rsync 'username#hostname:path/to/dir/*.txt' .
(notice the quotes: if you omit them, your shell will try to expand the *.txt part locally, will fail and give you an error.)
Useful flags:
--progress: show a progress bar
--append: if a file has only partially downloaded, resume it where it left off
I find the rsync utility so useful, I've created an alias for it in my shell and use it as a 'super-copy':
alias cpa 'rsync -vae ssh --progress --append'
With that alias, copying files between machines is just as easy as copying files locally:
cpa user#host:file .
Making it even better
Since rsync is using SSH, it helps to setup a private/public key pair, so you don't have to type in your password every time:
How do I setup Public-Key Authentication?
Futhermore, you can write down your username in your .ssh/config file and give the remote host a short name: read about it here.
For example, I have something like this:
Host panda
Hostname panda.server.long.hostname.com
User rodin
With this setup, my command to download files from the panda server is just:
cpa panda:path/to/my/files .
And there was much rejoicing.

process a file remotely using ssh

I have this report.tex file which I convert to pdf as follows:
latex report.tex
dvips report.dvi -o report.ps
ps2pdfwr report.ps report.pdf
These commands are placed in a file called linux_build
This works great. However, this works on my Linux machine and most of my work I do on my Mac
I checked out MacTex which is enormous (> 4GB) so I decided to process the latex file remotely (so working on my Mac, and building on my Linux computer). Like this:
ssh latex#192.168.2.8 "cd build && ./linux_build" < report.tex
scp latex#192.168.2.8:build/report.pdf .
All this works, except for one thing:
latex report.tex
That command simply looks on disk, not for some input stream/pipe of whatever. It is at this point I'm not sure anymore how to fix this. Any suggestions ?
scp report.tex latex#192.168.2.8:/home/Jeanluca/build
ssh latex#192.168.2.8 "cd build && ./linux_build" < report.tex
scp latex#192.168.2.8:build/report.pdf
Try sending your tex file over first. To the full path for the build directory.
I know your frustration. It grew so big that I put together a small script which efficiently runs LaTeX on a remote server.
It prestarts LaTeX on the remote end with the preamble of the previous run such that LaTeX has already loaded the required packages and is ready to go when changed contents arrives, and starts streaming the resulting PDF file immediately (before LaTeX has finished writing to it). Also dependencies (images, included source files etc.) are transparently handled.
Maybe you too find it useful: https://github.com/iblech/sshlatex
No installation is necessary. Execution is simple:
$ sshlatex ssh.example.org foo.tex
If latex supports reading from standard input then you can do it that way.
Possibly just latex or maybe latex - or possibly latex /dev/stdin to fake it as a local file.
If that doesn't work then you need to transfer the file over first.

"Spoof" File Extension In Bash

Is there a way to "spoof" the file extension of a file in bash for consumption by another program? I can think of doing some shell scripting and making lots of soft-links, but that isn't very scalable.
Let's imagine I have a program I'm trying to use that requires input files to be of a specific file extension, and it has no method of turning off this check.
You could make a fifo with the requisite extension and cat any other file type into it. So, if your crazy program needs to see files that end in .funky, you can do this:
mkfifo file.funky
cat someotherfile > file.funky &
someprogram file.funky
Create a symbolic link for each file you want to have a particular extension, then pass the name of the symlink to the command.
For example suppose you have files with names of the form *.foo and you need to refer to them with extensions of .bar:
for file in *.foo ; do
ln -s $file _$$_$file.bar
done
I precede each symlink name with _$$_ to avoid the possibility of colliding with an existing file name (you don't want to do ln -s file.foo file.bar if file.bar already exists).
With a little more programming, your script can keep track of which symlinks it created and, if you like, clean them up after executing the command.
This assumes, as you stated in the question, that the command can't be forced to accept a different extension.
You could, without too much difficulty, create a wrapper script that replaces the command in question, creating the symlinks, invoking the command, and cleaning up after itself automatically.

Resources