I am trying to create a custom script to control my CANON SELPHY PRINTER form the command-line.
lp -d Canon_CP900 -o media="CP_C_size" /Users/sangyookim/Desktop/selphy.jpg
I have the tested the above code and it's working perfectly as I intend it to.
But I have stumbled upon a problem.
When I replace the /Users/sangyookim/Desktop/selphy.jpg or filname to a web link such as the below, it will return me unable to access.. No such file or directory
http://res.cloudinary.com/splexz/image/upload/v1447239237/yer60xuvd6nmeldcbivd.png
How can I print images from the web using CUPS command line?
You cannot directly print a remote web page (because most Linux commands, lp included, do not know about URLs).
At least, you'll need to first fetch that web page using a command line HTTP client like wget or curl, then use another command (with lp or lpr) to print it (and perhaps later remove that downloaded file from your local filesystem).
For images, you probably would need some converter before printing them, e.g. the convert command from ImageMagick (which happens to understand URLs, thanks to Mark Setchell for commenting on this), to convert them to some .pdf or perhaps .ps file (unless you have configured lp or CUPS to do the conversion automagically). Maybe you could use a2ps
You could write some script (or shell function) to do all the job.
In limited cases, you might also consider using some network file systems NFS, CIFS or set up some FUSE (I don't recommend that).
Related
I am a Linux newbie and I often find myself working with a bunch of random data.
For example: I would like to work on a sample text file to try out some regular expressions or read some data into gnuplot from some sample data in a csv file or something.
I normally do this by copying and pasting passages from the internet but I was wondering if there exists some combination of commands that would allow me to do this without having to leave the terminal. I was thinking about using something like the curl command but I dont exactly know how it works...
To my knowledge there are websites that host content. I would simply like to access them and store them in my computer.
In conclusion and as a concrete example, how would i copy and paste a random passage off the internet from a website and store it in a file in my system using only the command line? Maybe you can point me in the right direction. Thanks.
You could redirect the output of a curl command into a file e.g.
curl https://run.mocky.io/v3/5f03b1ef-783f-439d-b8c5-bc5ad906cb14 > data-output
Note that I've mocked data in Mocky which is a nice website for quickly mocking an API.
I normally use "Project Gutenberg" which has 60,000+ books freely downloadable online.
So, if I want the full text of "Peter Pan and Wendy" by J.M. Barrie, I'd do:
curl "http://www.gutenberg.org/files/16/16-0.txt" > PeterPan.txt
If you look at the page for that book, you can see how to get it as HTML, plain text, ePUB or UTF-8.
Basically I am trying to get list of programs in Linux which are installed and can open particular file extension .jpg for example. If not all, At-least default program should get listed.
Linux (the kernel) has no knowledge on file types to application mapping. If you want to use Gnome programs you can look at https://people.gnome.org/~shaunm/admin-guide/mimetypes-7.html. For KDE there is another mechanism. Each toolkit can define it as it likes. And the programmer can use the defaults or not. So it is simply application specific!
What do you want to achieve?
If you (double) click with a explorer/browser application on an icon or file name, exactly the explorer/browser looks for the file type. Typically this is realized via mime type dictionary. But how a program looks for the file type and maybe execute another program is only related to the programmer who writes that program. The GUI tool-chains like Gnome and KDE have a lot of support for that topic and so you have basic conformity for each family of applications.
If you want to know how a application do the job, start it with strace. But it is quite hard to dig into the huge amount of data.
Also you can take a look for xdg-open. Many programs use this helper to start applications. As an example: If you start Dolphin with strace you will find a line like lstat64("/etc/xdg", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 after clicking on a file.
you can run from command line with:
xdg-open <file-name>
You maybe also want to have a look for applications which registers for file types: /usr/share/applications/*.desktop
Here you can find in each desktop file some mime-types which are registered for the applications. E.g. for audiacity is:
MimeType=application/x-audacity-project;audio/flac;audio/x-flac;audio/basic;audio/x-aiff;audio/x-wav;application/ogg;audio/x-vorbis+ogg;
For your example with jpg:
$ xdg-mime query filetype <any-jpg-file>
image/jpeg
$ grep 'image/jpeg' -R /usr/share/applications/*
...
/usr/share/applications/mimeinfo.cache:image/jpeg2000=kde4-kolourpaint.desktop;gimp.desktop;
So you can see that gimp is one of the default applications for jpg
The place to start looking is at the mailcap (/etc/mailcap) and MIME-types, e.g., in /etc/mime.types in Debian (the filename and path will vary according to who provides it).
The mailcap file gives some rules for opening a file, while MIME-types lists the known filetypes with a tag that allows multiple applications to know about the file types.
Except for embedded or reduced-functionality systems (such as those based on busybox), you would find these files on almost every UNIX-like system.
(no alternate suggestions like vim --servername, or vim over ssh, or "just use ssh", or nfs, sshfs please. Also I prefer to avoid more elaborate incarnations of netcat like ncat)
I'd like to edit my text files that exist on another computer over a network, and know that it's not so straightforward using netcat. But I'm sure it's possible given a deeper understanding of netcat. I'd like to achieve that deeper understanding.
I know how to create my own REST service with netcat using pipes and fifo's. I also know you can expose your entire bash shell over netcat (yes it's dangerous), but it won't display the prompt. Yet it does display the output of a bash command back on the client.
What must be done to get a text editor (like vim, pico, nano, emacs) to work over a network for both reading and writing?
From vim doc:
Editing files over a network *new-network-files*
----------------------------
Files starting with scp://, rcp://, ftp:// and http:// are recognized as
remote files. An attempt is made to access these files with the indicated
method. For http:// only reading is possible, for the others writing is also
supported. Uses the netrw.vim script as a standard "plugin". |netrw|
Another tutorial: http://vim.wikia.com/wiki/Edit_remote_files_locally_via_SCP/RCP/FTP
# open a remote file
vim scp://remote-computer:22//tmp/file.txt
# ... EDIT ...
# write it back (run in vim)
:Nwrite
I am developing a Qt application in Linux. I wanted to pass Linux commands to a terminal. That worked but now i also want to get a response from the terminal for this specific command.
For example,
ls -a
As you know this command lists the directories and files of the current working directory. I now want to pass the returned values from the ls call to my application. What is a correct way to do this?
QProcess is the qt class that will let you spawn a process and read the result. There's an example of usage for reading the result of a command on that page.
popen() , api of linux systerm , return FILE * that you can read it like a file descriptor, may help youp erhaps。
Parsing ls(1) output is dangerous -- make a few files with funny names in a directory and test it out:
touch "one file"
touch "`printf "\x0a\x0a\x0ahello\x0a world"`"
That creates two files in the current working directory. I expect your attempts to parse ls(1) output won't work. This might be alright if you're showing the results to a human, (though a human will be immensely confused if a filename includes output that looks just like ls(1) output!) but if you're trying to present something like an explorer.exe or Finder.app representation of files in the filesystem, this is horribly broken.
Instead, use opendir(3), readdir(3), and closedir(3) to read directory entries yourself. This will be safer, more portable, and (as a side benefit) slightly better performing.
I am writing a script on Red Hat Linux (I forget the version) that needs a header, but the banner command is not there for me to use and I won't be able to get it installed. I read via Google that it may well have been deprecated.
So is there a new version of the command that produces similar results, or a way I can replicate the command, or even just temporarily change the script output so that characters are a different size?
I've tried looking at stty but we don't access via xterm, we log in directly via putty.
In its simplest form, 'banner' is less than a few pages of code (e.g. this one). Perhaps you could just compile and run it from your home directory?
Use some web site, for example http://patorjk.com/software/taag/.
If you need it frequently you can create a script to scrap the result.
BTW, stty has nothing to do with your problem, I don't know why you mentioned it.